home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / packages / info.el.z / info.el
Encoding:
Text File  |  1998-05-21  |  96.6 KB  |  2,779 lines

  1. ;;; info.el --- info package for Emacs.
  2. ;; Keywords: help
  3.  
  4. ;; Copyright (C) 1985, 1986, 1993, 1997 Free Software Foundation, Inc.
  5.  
  6. ;; Author: Dave Gillespie <daveg@synaptics.com>
  7. ;;       Richard Stallman <rms@gnu.ai.mit.edu>
  8. ;; Maintainer: Dave Gillespie <daveg@synaptics.com>
  9. ;; Version: 1.07 of 7/22/93
  10. ;; Keywords: docs, help
  11.  
  12. ;; This file is part of XEmacs.
  13.  
  14. ;; XEmacs is free software; you can redistribute it and/or modify it
  15. ;; under the terms of the GNU General Public License as published by
  16. ;; the Free Software Foundation; either version 2, or (at your option)
  17. ;; any later version.
  18.  
  19. ;; XEmacs is distributed in the hope that it will be useful, but
  20. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22. ;; General Public License for more details.
  23.  
  24. ;; You should have received a copy of the GNU General Public License
  25. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  26. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  27. ;; Boston, MA 02111-1307, USA.
  28.  
  29. ;;; Synched up with: Not synched with FSF.
  30.  
  31. ;; Commentary:
  32.  
  33. ;; This is based on an early Emacs 19 info.el file.
  34. ;;
  35. ;; Note that Info-directory has been replaced by Info-directory-list,
  36. ;; a search path of directories in which to find Info files.
  37. ;; Also, Info tries adding ".info" to a file name if the name itself
  38. ;; is not found.
  39. ;;
  40. ;; See the change log below for further details.
  41.  
  42.  
  43. ;; LCD Archive Entry:
  44. ;; info-dg|Dave Gillespie|daveg@synaptics.com
  45. ;; |Info reader with many enhancements; replaces standard info.el.
  46. ;; |93-07-22|1.07|~/modes/info.el
  47.  
  48. ;; Also available from anonymous FTP on csvax.cs.caltech.edu.
  49.  
  50.  
  51. ;; Change Log:
  52.  
  53. ;; Modified 3/7/1991 by Dave Gillespie:
  54. ;; (Author's address: daveg@synaptics.com or daveg@csvax.cs.caltech.edu)
  55. ;;
  56. ;; Added keys:  i, t, <, >, [, ], {, }, 6, 7, 8, 9, 0.
  57. ;; Look at help for info-mode (type ? in Info) for descriptions.
  58. ;;
  59. ;; If Info-directory-list is undefined and there is no INFOPATH
  60. ;; in the environment, use value of Info-directory for compatibility
  61. ;; with Emacs 18.57.
  62. ;;
  63. ;; All files named "localdir" found in the path are appended to "dir",
  64. ;; the Info directory.  For this to work, "dir" should contain only
  65. ;; one node (Top), and each "localdir" should contain no ^_ or ^L
  66. ;; characters.  Generally they will contain only one or several
  67. ;; additional lines for the top-level menu.  Note that "dir" is
  68. ;; modified in memory each time it is loaded, but not on disk.
  69. ;;
  70. ;; If "dir" contains a line of the form:  "* Locals:"
  71. ;; then the "localdir"s are inserted there instead of at the end.
  72.  
  73.  
  74. ;; Modified 4/3/1991 by Dave Gillespie:
  75. ;;
  76. ;; Added Info-mode-hook (suggested by Sebastian Kremer).
  77. ;; Also added epoch-info-startup/select-hooks from Simon Spero's info.el.
  78. ;;
  79. ;; Added automatic decoding of compressed Info files.
  80. ;; See documentation for the variable Info-suffix-list.  Default is to
  81. ;; run "uncompress" on ".Z" files and "unyabba" on ".Y" files.
  82. ;; (See comp.sources.unix v24i073-076 for yabba/unyabba, a free software
  83. ;; alternative to compress/uncompress.)
  84. ;; Note: "dir" and "localdir" files should not be compressed.
  85. ;;
  86. ;; Changed variables like Info-enable-edit to be settable by M-x set-variable.
  87. ;;
  88. ;; Added Info-auto-advance variable.  If t, SPC and DEL will act like
  89. ;; } and {, i.e., they advance to the next/previous node if at the end
  90. ;; of the buffer.
  91. ;;
  92. ;; Changed `u' to restore point to most recent location in that node.
  93. ;; Added `=' to do this manually at any time.  (Suggested by David Fox).
  94. ;;
  95. ;; Changed `m' and `0-9' to try interpreting menu name as a file name
  96. ;; if not found as a node name.  This allows (dir) menus of the form,
  97. ;;     Emacs::        Cool text editor
  98. ;; as a shorthand for
  99. ;;     Emacs:(emacs).    Cool text editor
  100. ;;
  101. ;; Enhanced `i' to use line-number information in the index.
  102. ;; Added `,' to move among all matches to a previous `i' command.
  103. ;;
  104. ;; Added `a' (Info-annotate) for adding personal notes to any Info node.
  105. ;; Notes are not stored in the actual Info files, but in the user's own
  106. ;; ~/.infonotes file.
  107. ;;
  108. ;; Added Info-footnote-tag, made default be "Ref" instead of "Note".
  109. ;;
  110. ;; Got mouse-click stuff to work under Emacs version 18.  Check it out!
  111. ;; Left and right clicks scroll the Info window.
  112. ;; Middle click goes to clicked-on node, e.g., "Next:", a menu, or a note.
  113.  
  114.  
  115. ;; Modified 6/29/1991 by Dave Gillespie:
  116. ;;
  117. ;; Renamed epoch-info-startup/select-hooks to Info-startup/select-hook.
  118. ;;
  119. ;; Made Info-select-node into a command on the `!' key.
  120. ;;
  121. ;; Added Info-mouse-support user option.
  122. ;;
  123. ;; Cleaned up the implementation of some routines.
  124. ;;
  125. ;; Added special treatment of quoted words in annotations:  The `g'
  126. ;; command for a nonexistent node name scans for an annotation
  127. ;; (in any node of any file) containing that name in quotes:  g foo RET
  128. ;; looks for an annotation containing:  "foo"  or:  <<foo>>
  129. ;; If found, it goes to that file and node.
  130. ;;
  131. ;; Added a call to set up Info-directory-list in Info-find-node to
  132. ;; work around a bug in GNUS where it calls Info-goto-node before info.
  133. ;;
  134. ;; Added completion for `g' command (inspired by Richard Kim's infox.el).
  135. ;; Completion knows all node names for the current file, and all annotation
  136. ;; tags (see above).  It does not complete file names or node names in
  137. ;; other files.
  138. ;;
  139. ;; Added `k' (Info-emacs-key) and `*' (Info-elisp-ref) commands.  You may
  140. ;; wish to bind these to global keys outside of Info mode.
  141. ;;
  142. ;; Allowed localdir files to be full dir-like files; only the menu part
  143. ;; of each localdir is copied.  Also, redundant menu items are omitted.
  144. ;;
  145. ;; Changed Info-history to hold only one entry at a time for each node,
  146. ;; and to be circular so that multiple `l's come back again to the most
  147. ;; recent node.  Note that the format of Info-history entries has changed,
  148. ;; which may interfere with external programs that try to operate on it.
  149. ;; (Also inspired by Kim's infox.el).
  150. ;;
  151. ;; Changed `n', `]', `l', etc. to accept prefix arguments to move several
  152. ;; steps at once.  Most accept negative arguments to move oppositely.
  153. ;;
  154. ;; Changed `?' to bury *Help* buffer afterwards to keep it out of the way.
  155. ;;
  156. ;; Rearranged `?' key's display to be a little better for new users.
  157. ;;
  158. ;; Changed `a' to save whole window configuration and restore on C-c C-c.
  159. ;;
  160. ;; Fixed the bug reported by Bill Reynolds on gnu.emacs.bugs.
  161. ;;
  162. ;; Changed Info-last to restore window-start as well as cursor position.
  163. ;;
  164. ;; Changed middle mouse button in space after end of node to do Info-last
  165. ;; if we got here by following a cross reference, else do Info-global-next.
  166. ;;
  167. ;; Added some new mouse bindings: shift-left = Info-global-next,
  168. ;; shift-right = Info-global-prev, shift-middle = Info-last.
  169. ;;
  170. ;; Fixed Info-follow-reference not to make assumptions about length
  171. ;; of Info-footnote-tag [Linus Tolke].
  172. ;;
  173. ;; Changed default for Info-auto-advance mode to be press-twice-for-next-node.
  174. ;;
  175. ;; Modified x-mouse-ignore to preserve last-command variable, so that
  176. ;; press-twice Info-auto-advance mode works with the mouse.
  177.  
  178.  
  179. ;; Modified 3/4/1992 by Dave Gillespie:
  180. ;;
  181. ;; Added an "autoload" command to help autoload.el.
  182. ;;
  183. ;; Changed `*' command to look for file `elisp' as well as for `lispref'.
  184. ;;
  185. ;; Fixed a bug involving footnote names containing regexp special characters.
  186. ;;
  187. ;; Fixed a bug in completion during `f' (or `r') command.
  188. ;;
  189. ;; Added TAB (Info-next-reference), M-TAB, and RET keys to Info mode.
  190. ;;
  191. ;; Added new bindings, `C-h C-k' for Info-emacs-key and `C-h C-f' for
  192. ;; Info-elisp-ref.  These bindings are made when info.el is loaded, and
  193. ;; only if those key sequences were previously unbound.  These bindings
  194. ;; work at any time, not just when Info is already running.
  195.  
  196.  
  197. ;; Modified 3/8/1992 by Dave Gillespie:
  198. ;;
  199. ;; Fixed some long lines that were causing trouble with mailers.
  200.  
  201.  
  202. ;; Modified 3/9/1992 by Dave Gillespie:
  203. ;;
  204. ;; Added `C-h C-i' (Info-query).
  205. ;;
  206. ;; Added Info-novice mode, warns if the user attempts to switch to
  207. ;; a different Info file.
  208. ;;
  209. ;; Fixed a bug that caused problems using compressed Info files
  210. ;; and Info-directory-list at the same time.
  211. ;;
  212. ;; Disabled Info-mouse-support by default if Epoch or Hyperbole is in use.
  213. ;;
  214. ;; Added an expand-file-name call to Info-find-node to fix a small bug.
  215.  
  216.  
  217. ;; Modified 5/22/1992 by Dave Gillespie:
  218. ;;
  219. ;; Added "standalone" operation:  "emacs -f info" runs Emacs specifically
  220. ;; for use as an Info browser.  In this mode, the `q' key quits Emacs
  221. ;; itself.  Also, "emacs -f info arg" starts in Info file "arg" instead
  222. ;; of "dir".
  223. ;;
  224. ;; Changed to prefer "foo.info" over "foo".  If both exist, "foo" is
  225. ;; probably a directory or executable program!
  226. ;;
  227. ;; Made control-mouse act like regular-mouse does in other buffers.
  228. ;; (In most systems, this will be set-cursor for left-mouse, x-cut
  229. ;; for right-mouse, and x-paste, which will be an error, for
  230. ;; middle-mouse.)
  231. ;;
  232. ;; Improved prompting and searching for `,' key.
  233. ;;
  234. ;; Fixed a bug where some "* Menu:" lines disappeared when "dir"
  235. ;; contained several nodes.
  236.  
  237.  
  238. ;; Modified 9/10/1992 by Dave Gillespie:
  239. ;;
  240. ;; Mixed in support for XEmacs.  Mouse works the same as in
  241. ;; the other Emacs versions by default; added Info-lucid-mouse-style
  242. ;; variable, which enables mouse operation similar to XEmacs's default.
  243. ;;
  244. ;; Fixed a bug where RET couldn't understand "* Foo::" if "Foo" was a
  245. ;; file name instead of a node name.
  246. ;;
  247. ;; Added `x' (Info-bookmark), a simple interface to the annotation
  248. ;; tags feature.  Added `j' (Info-goto-bookmark), like `g' but only
  249. ;; completes bookmarks.
  250. ;;
  251. ;; Added `<<tag>>' as alternate to `"tag"' in annotations.
  252. ;;
  253. ;; Added `v' (Info-visit-file), like Info-goto-node but specialized
  254. ;; for going to a new Info file (with file name completion).
  255. ;;
  256. ;; Added recognition of gzip'd ".z" files.
  257.  
  258.  
  259. ;; Modified 5/9/1993 by Dave Gillespie:
  260. ;;
  261. ;; Merged in various things from FSF's latest Emacs 19 info.el.
  262. ;; Notably:  Added Info-default-directory-list.
  263.  
  264.  
  265. ;; Modified 6/2/1993 by Dave Gillespie:
  266. ;;
  267. ;; Changed to use new suffix ".gz" for gzip files.
  268.  
  269.  
  270. ;; Modified 7/22/1993 by Dave Gillespie:
  271. ;;
  272. ;; Changed Info-footnote-tag to "See" instead of "Ref".
  273. ;;
  274. ;; Extended Info-fontify-node to work with FSF version of Emacs 19.
  275.  
  276. ;; Modified 7/30/1993 by Jamie Zawinski:
  277. ;;
  278. ;; Commented out the tty and fsf19 mouse support, because why bother.
  279. ;; Commented out the politically incorrect version of XEmacs mouse support.
  280. ;; Commented out mouse scrolling bindings because the party line on that
  281. ;;  is "scrollbars are coming soon."
  282. ;; Commented out munging of help-for-help's doc; put it in help.el.
  283. ;; Did Info-edit-map the modern XEmacs way.
  284. ;; Pruned extra cruft from fontification and mouse handling code.
  285. ;; Fixed ASCII-centric bogosity in unreading of events.
  286.  
  287. ;; Modified 8/11/95 by Chuck Thompson:
  288. ;;
  289. ;; Removed any pretense of ever referencing Info-directory since it
  290. ;; wasn't working anyhow.
  291.  
  292. ;; Modified 4/5/97 by Tomasz J. Cholewo:
  293. ;;
  294. ;; Modified Info-search to use with-caps-disable-folding
  295.  
  296. ;; Modified 6/21/97 by Hrvoje Niksic
  297. ;;
  298. ;; Fixed up Info-next-reference to work sanely when n < 0.
  299. ;; Added S-tab binding.
  300.  
  301. ;; Modified 1997-07-10 by Karl M. Hegbloom
  302. ;;
  303. ;; Added `Info-minibuffer-history'
  304. ;; (also added to defaults in "lisp/utils/savehist.el")
  305. ;;  Other changes in main ChangeLog.
  306.  
  307. ;; Code:
  308.  
  309. (defgroup info nil
  310.   "The info package for Emacs."
  311.   :group 'help
  312.   :group 'docs)
  313.  
  314. (defgroup info-faces nil
  315.   "The faces used by info browser."
  316.   :group 'info
  317.   :group 'faces)
  318.  
  319.  
  320. (defcustom Info-inhibit-toolbar nil
  321.   "*Non-nil means don't use the specialized Info toolbar."
  322.   :type 'boolean
  323.   :group 'info)
  324.  
  325. (defcustom Info-novice nil
  326.   "*Non-nil means to ask for confirmation before switching Info files."
  327.   :type 'boolean
  328.   :group 'info)
  329.  
  330. (defvar Info-history nil
  331.   "List of info nodes user has visited.
  332. Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
  333.  
  334. (defvar Info-keeping-history t
  335.   "Non-nil if Info-find-node should modify Info-history.
  336. This is for use only by certain internal Info routines.")
  337.  
  338. (defvar Info-minibuffer-history nil
  339.   "Minibuffer history for Info.")
  340.  
  341. (defcustom Info-enable-edit nil
  342.   "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info
  343. can edit the current node.
  344. This is convenient if you want to write info files by hand.
  345. However, we recommend that you not do this.
  346. It is better to write a Texinfo file and generate the Info file from that,
  347. because that gives you a printed manual as well."
  348.   :type 'boolean
  349.   :group 'info)
  350.  
  351. (defcustom Info-enable-active-nodes t
  352.   "*Non-nil allows Info to execute Lisp code associated with nodes.
  353. The Lisp code is executed when the node is selected."
  354.   :type 'boolean
  355.   :group 'info)
  356.  
  357. (defcustom Info-restoring-point t
  358.   "*Non-nil means to restore the cursor position when re-entering a node."
  359.   :type 'boolean
  360.   :group 'info)
  361.  
  362. (defcustom Info-auto-advance 'twice
  363.   "*Control what SPC and DEL do when they can't scroll any further.
  364. If nil, they beep and remain in the current node.
  365. If t, they move to the next node (like Info-global-next/prev).
  366. If anything else, they must be pressed twice to move to the next node."
  367.   :type '(choice (const :tag "off" nil)
  368.          (const :tag "advance" t)
  369.          (const :tag "confirm" twice))
  370.   :group 'info)
  371.  
  372. (defcustom Info-fontify t
  373.   "*Non-nil enables font features in XEmacs.
  374. This variable is ignored unless running under XEmacs."
  375.   :type 'boolean
  376.   :group 'info)
  377.  
  378. (defvar Info-default-directory-list nil
  379.   "*List of directories to search for Info documents, and `dir' or `localdir' files.
  380. The value of `Info-default-directory-list' will be initialized to a
  381. reasonable default by the startup code, and usually doesn't need to be
  382. changed in your personal configuration, though you may do so if you like.
  383.  
  384. The first directory on this list must contain a `dir' file like the one
  385. supplied with XEmacs, which will be used as the (dir)Top node.
  386.  
  387. For more information, see the documentation to the variable:
  388. `Info-directory-list'.")
  389.  
  390. (defcustom Info-additional-search-directory-list nil
  391.   "*List of additional directories to search for Info documentation
  392. files.  These directories are not searched for merging the `dir'
  393. file. An example might be something like:
  394. \"/usr/local/lib/xemacs/packages/lisp/calc/\""
  395.   :type '(repeat directory)
  396.   :group 'info)
  397.  
  398. (defvar Info-emacs-info-file-name "xemacs.info"
  399.   "The filename of the XEmacs info for
  400. `Info-goto-emacs-command-node' (`\\<help-mode-map>\\[Info-goto-emacs-command-node]')")
  401.  
  402. (defvar Info-directory-list
  403.   (let ((path (getenv "INFOPATH")))
  404.     (if path
  405.     (split-string path path-separator)
  406.       Info-default-directory-list))
  407.   "List of directories to search for Info documentation files.
  408. Default is to use the environment variable INFOPATH if it exists,
  409. else to use `Info-default-directory-list'.
  410. The first directory in this list, the \"dir\" file there will become
  411. the (dir)Top node of the Info documentation tree.")
  412.  
  413. (defcustom Info-localdir-heading-regexp
  414.     "^Locally installed XEmacs Packages:?"
  415.   "The menu part of localdir files will be inserted below this topic
  416. heading."
  417.   :type 'regexp
  418.   :group 'info)
  419.  
  420. (defface info-node '((t (:bold t :italic t)))
  421.   "Face used for node links in info."
  422.   :group 'info-faces)
  423.  
  424. (defface info-xref '((t (:bold t)))
  425.   "Face used for cross-references in info."
  426.   :group 'info-faces)
  427.  
  428. ;; Is this right for NT?  .zip, with -c for to stdout, right?
  429. (defvar Info-suffix-list '( ("" . nil) 
  430.                 (".info" . nil)
  431.                 (".info.gz" . "gzip -dc %s")
  432.                 (".info-z" . "gzip -dc %s")
  433.                 (".info.Z" . "uncompress -c %s")
  434.                 (".gz" . "gzip -dc %s")
  435.                 (".Z" . "uncompress -c %s")
  436.                 (".zip" . "unzip -c %s") )
  437.   "List of file name suffixes and associated decoding commands.
  438. Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
  439. changed to name of the file to decode, otherwise the file is given to
  440. the command as standard input.  If STRING is nil, no decoding is done.")
  441.  
  442. (defvar Info-footnote-tag "Note"
  443.   "*Symbol that identifies a footnote or cross-reference.
  444. All \"*Note\" references will be changed to use this word instead.")
  445.  
  446. (defvar Info-current-file nil
  447.   "Info file that Info is now looking at, or nil.
  448. This is the name that was specified in Info, not the actual file name.
  449. It doesn't contain directory names or file name extensions added by Info.")
  450.  
  451. (defvar Info-current-subfile nil
  452.   "Info subfile that is actually in the *info* buffer now,
  453. or nil if current info file is not split into subfiles.")
  454.  
  455. (defvar Info-current-node nil
  456.   "Name of node that Info is now looking at, or nil.")
  457.  
  458. (defvar Info-tag-table-marker (make-marker)
  459.   "Marker pointing at beginning of current Info file's tag table.
  460. Marker points nowhere if file has no tag table.")
  461.  
  462. (defvar Info-current-file-completions nil
  463.   "Cached completion list for current Info file.")
  464.  
  465. (defvar Info-current-annotation-completions nil
  466.   "Cached completion list for current annotation files.")
  467.  
  468. (defvar Info-index-alternatives nil
  469.   "List of possible matches for last Info-index command.")
  470. (defvar Info-index-first-alternative nil)
  471.  
  472. (defcustom Info-annotations-path '("~/.xemacs/info.notes"
  473.                                    "~/.infonotes"
  474.                    "/usr/lib/info.notes")
  475.   "*Names of files that contain annotations for different Info nodes.
  476. By convention, the first one should reside in your personal directory.
  477. The last should be a world-writable \"public\" annotations file."
  478.   :type '(repeat file)
  479.   :group 'info)
  480.  
  481. (defcustom Info-button1-follows-hyperlink nil
  482.   "*Non-nil means mouse button1 click will follow hyperlink."
  483.   :type 'boolean
  484.   :group 'info)
  485.  
  486. (defvar Info-standalone nil
  487.   "Non-nil if Emacs was started solely as an Info browser.")
  488.  
  489. (defvar Info-in-cross-reference nil)
  490. (defvar Info-window-configuration nil)
  491.  
  492. ;;;###autoload
  493. (defun info (&optional file)
  494.   "Enter Info, the documentation browser.
  495. Optional argument FILE specifies the file to examine;
  496. the default is the top-level directory of Info.
  497.  
  498. In interactive use, a prefix argument directs this command
  499. to read a file name from the minibuffer."
  500.   (interactive (if current-prefix-arg
  501.            (list (read-file-name "Info file name: " nil nil t))))
  502.   (let ((p command-line-args))
  503.     (while p
  504.       (and (string-match "^-[fe]" (car p))
  505.        (equal (nth 1 p) "info")
  506.        (not Info-standalone)
  507.        (setq Info-standalone t)
  508.        (= (length p) 3)
  509.        (not (string-match "^-" (nth 2 p)))
  510.        (setq file (nth 2 p))
  511.        (setq command-line-args-left nil))
  512.       (setq p (cdr p))))
  513. ;  (Info-setup-x) ??? What was this going to be?  Can anyone tell karlheg?
  514.   (if file
  515.       (unwind-protect
  516.       (Info-goto-node (concat "(" file ")"))
  517.     (and Info-standalone (info)))
  518.     (if (get-buffer "*info*")
  519.     (switch-to-buffer "*info*")
  520.       (Info-directory))))
  521.  
  522. ;;;###autoload
  523. (defun Info-query (file)
  524.   "Enter Info, the documentation browser.  Prompt for name of Info file."
  525.   (interactive "sInfo topic (default = menu): ")
  526.   (info)
  527.   (if (equal file "")
  528.       (Info-goto-node "(dir)")
  529.     (Info-goto-node (concat "(" file ")"))))
  530.  
  531. (defun Info-setup-initial ()
  532.   (let ((f Info-annotations-path))
  533.     (while f
  534.       (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
  535.       (bury-buffer (find-file-noselect (car f))))
  536.       (setq f (cdr f)))))
  537.  
  538. (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
  539.   "Go to an info node specified as separate FILENAME and NODENAME.
  540. Look for a plausible filename, or if not found then look for URL's and
  541. dispatch to the appropriate fn.  NO-GOING-BACK is non-nil if
  542. recovering from an error in this function; it says do not attempt
  543. further (recursive) error recovery.  TRYFILE is ??"
  544.  
  545.   (Info-setup-initial)
  546.  
  547.   (cond
  548.    ;; empty filename is simple case
  549.    ((null filename)
  550.     (Info-find-file-node nil nodename no-going-back tryfile line))
  551.    ;; Convert filename to lower case if not found as specified.
  552.    ;; Expand it, look harder...
  553.    ((let (temp temp-downcase found 
  554.            (fname (substitute-in-file-name filename)))
  555.       (let ((dirs (cond
  556.            ((string-match "^\\./" fname) ; If specified name starts with `./'
  557.             (list default-directory)) ; then just try current directory.
  558.            ((file-name-absolute-p fname)
  559.             '(nil))        ; No point in searching for an absolute file name
  560.            (Info-additional-search-directory-list
  561.             (append Info-directory-list
  562.                 Info-additional-search-directory-list))
  563.            (t Info-directory-list))))
  564.     ;; Search the directory list for file FNAME.
  565.     (while (and dirs (not found))
  566.       (setq temp (expand-file-name fname (car dirs)))
  567.       (setq temp-downcase
  568.         (expand-file-name (downcase fname) (car dirs)))
  569.       (if (equal temp-downcase temp) (setq temp-downcase nil))
  570.       ;; Try several variants of specified name.
  571.       ;; Try downcasing, appending a suffix, or both.
  572.       (setq found (Info-suffixed-file temp temp-downcase))
  573.       (setq dirs (cdr dirs)))
  574.     (if found 
  575.         (progn (setq filename (expand-file-name found))
  576.            t))))
  577.     (Info-find-file-node filename nodename no-going-back tryfile line))
  578.    ;; Look for a URL.  This pattern is stolen from w3.el to prevent
  579.    ;; loading it if we won't need it.
  580.    ((string-match  (concat "^\\(wais\\|solo\\|x-exec\\|newspost\\|www\\|"
  581.                "mailto\\|news\\|tn3270\\|ftp\\|http\\|file\\|"
  582.                "telnet\\|gopher\\):")
  583.            filename)
  584.     (browse-url filename))
  585.    (t
  586.     (error "Info file %s does not exist" filename))))
  587.  
  588. (defun Info-find-file-node (filename nodename
  589.                      &optional no-going-back tryfile line)
  590.   ;; This is the guts of what was Info-find-node. Whoever wrote this
  591.   ;; should be locked up where they can't do any more harm.
  592.  
  593.   ;; Go into info buffer.
  594.   (switch-to-buffer "*info*")
  595.   (buffer-disable-undo (current-buffer))
  596.   (run-hooks 'Info-startup-hook)
  597.   (or (eq major-mode 'Info-mode)
  598.       (Info-mode))
  599.   (or (null filename)
  600.       (equal Info-current-file filename)
  601.       (not Info-novice)
  602.       (string= "dir" (file-name-nondirectory Info-current-file))
  603.       (if (y-or-n-p-maybe-dialog-box
  604.        (format "Leave Info file `%s'? "
  605.            (file-name-nondirectory Info-current-file)))
  606.       (message "")
  607.     (keyboard-quit)))
  608.   ;; Record the node we are leaving.
  609.   (if (and Info-current-file (not no-going-back))
  610.       (Info-history-add Info-current-file Info-current-node (point)))
  611.   (widen)
  612.   (setq Info-current-node nil
  613.     Info-in-cross-reference nil)
  614.   (unwind-protect
  615.       (progn
  616.     ;; Switch files if necessary
  617.     (or (null filename)
  618.         (equal Info-current-file filename)
  619.         (let ((buffer-read-only nil))
  620.           (setq Info-current-file nil
  621.             Info-current-subfile nil
  622.             Info-current-file-completions nil
  623.             Info-index-alternatives nil
  624.             buffer-file-name nil)
  625.           (erase-buffer)
  626.           (if (string= "dir" (file-name-nondirectory filename))
  627.           (Info-insert-dir)
  628.         (Info-insert-file-contents filename t)
  629.         (setq default-directory (file-name-directory filename)))
  630.           (set-buffer-modified-p nil)
  631.           ;; See whether file has a tag table.  Record the location if yes.
  632.           (set-marker Info-tag-table-marker nil)
  633.           (goto-char (point-max))
  634.           (forward-line -8)
  635.           (or (equal nodename "*")
  636.           (not (search-forward "\^_\nEnd tag table\n" nil t))
  637.           (let (pos)
  638.             ;; We have a tag table.  Find its beginning.
  639.             ;; Is this an indirect file?
  640.             (search-backward "\nTag table:\n")
  641.             (setq pos (point))
  642.             (if (save-excursion
  643.               (forward-line 2)
  644.               (looking-at "(Indirect)\n"))
  645.             ;; It is indirect.  Copy it to another buffer
  646.             ;; and record that the tag table is in that buffer.
  647.             (save-excursion
  648.               (let ((buf (current-buffer)))
  649.                 (set-buffer
  650.                  (get-buffer-create " *info tag table*"))
  651.                 (buffer-disable-undo (current-buffer))
  652.                 (setq case-fold-search t)
  653.                 (erase-buffer)
  654.                 (insert-buffer-substring buf)
  655.                 (set-marker Info-tag-table-marker
  656.                     (match-end 0))))
  657.              (set-marker Info-tag-table-marker pos))))
  658.           (setq Info-current-file
  659.             (file-name-sans-versions buffer-file-name))))
  660.     (if (equal nodename "*")
  661.         (progn (setq Info-current-node nodename)
  662.            (Info-set-mode-line)
  663.            (goto-char (point-min)))
  664.       ;; Search file for a suitable node.
  665.       (let* ((qnode (regexp-quote nodename))
  666.          (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
  667.          (guesspos (point-min))
  668.          (found t))
  669.         ;; First get advice from tag table if file has one.
  670.         ;; Also, if this is an indirect info file,
  671.         ;; read the proper subfile into this buffer.
  672.         (if (marker-position Info-tag-table-marker)
  673.         (save-excursion
  674.           (set-buffer (marker-buffer Info-tag-table-marker))
  675.           (goto-char Info-tag-table-marker)
  676.           (if (re-search-forward regexp nil t)
  677.               (progn
  678.             (setq guesspos (read (current-buffer)))
  679.             ;; If this is an indirect file,
  680.             ;; determine which file really holds this node
  681.             ;; and read it in.
  682.             (if (not (eq (current-buffer) (get-buffer "*info*")))
  683.                 (setq guesspos
  684.                   (Info-read-subfile guesspos)))))))
  685.         (goto-char (max (point-min) (- guesspos 1000)))
  686.         ;; Now search from our advised position (or from beg of buffer)
  687.         ;; to find the actual node.
  688.         (catch 'foo
  689.           (while (search-forward "\n\^_" nil t)
  690.         (forward-line 1)
  691.         (let ((beg (point)))
  692.           (forward-line 1)
  693.           (if (re-search-backward regexp beg t)
  694.               (throw 'foo t))))
  695.           (setq found nil)
  696.           (let ((bufs (delq nil (mapcar 'get-file-buffer
  697.                         Info-annotations-path)))
  698.             (pattern (if (string-match "\\`<<.*>>\\'" qnode) qnode
  699.                    (format "\"%s\"\\|<<%s>>" qnode qnode)))
  700.             (pat2 (concat "------ *File: *\\([^ ].*[^ ]\\) *Node: "
  701.                   "*\\([^ ].*[^ ]\\) *Line: *\\([0-9]+\\)"))
  702.             (afile nil) anode aline)
  703.         (while (and bufs (not anode))
  704.           (save-excursion
  705.             (set-buffer (car bufs))
  706.             (goto-char (point-min))
  707.             (if (re-search-forward pattern nil t)
  708.             (if (re-search-backward pat2 nil t)
  709.                 (setq afile (buffer-substring (match-beginning 1)
  710.                               (match-end 1))
  711.                   anode (buffer-substring (match-beginning 2)
  712.                               (match-end 2))
  713.                   aline (string-to-int
  714.                      (buffer-substring (match-beginning 3)
  715.                                (match-end 3)))))))
  716.           (setq bufs (cdr bufs)))
  717.         (if anode
  718.             (Info-find-node afile anode t nil aline)
  719.           (if tryfile
  720.               (condition-case nil
  721.               (Info-find-node nodename "Top" t)
  722.             (error nil)))))
  723.           (or Info-current-node
  724.           (error "No such node: %s" nodename)))
  725.         (if found
  726.         (progn
  727.           (Info-select-node)
  728.           (goto-char (point-min))
  729.           (if line (forward-line line)))))))
  730.     ;; If we did not finish finding the specified node,
  731.     ;; go back to the previous one.
  732.     (or Info-current-node no-going-back
  733.     (let ((hist (car Info-history)))
  734.       ;; The following is no longer safe with new Info-history system
  735.       ;; (setq Info-history (cdr Info-history))
  736.       (Info-goto-node (car hist) t)
  737.       (goto-char (+ (point-min) (nth 1 hist)))))))
  738.  
  739. ;; Cache the contents of the (virtual) dir file, once we have merged
  740. ;; it for the first time, so we can save time subsequently.
  741. (defvar Info-dir-contents nil)
  742.  
  743. ;; Cache for the directory we decided to use for the default-directory
  744. ;; of the merged dir text.
  745. (defvar Info-dir-contents-directory nil)
  746.  
  747. ;; Record the file attributes of all the files from which we
  748. ;; constructed Info-dir-contents.
  749. (defvar Info-dir-file-attributes nil)
  750.  
  751. (defun Info-insert-dir ()
  752.   "Construct the Info directory node by merging the files named
  753. \"dir\" or \"localdir\" from the directories in `Info-directory-list'
  754. The \"dir\" files will take precedence in cases where both exist.  It
  755. sets the *info* buffer's `default-directory' to the first directory we
  756. actually get any text from."
  757.   (if (and Info-dir-contents Info-dir-file-attributes
  758.        ;; Verify that none of the files we used has changed
  759.        ;; since we used it.
  760.        (eval (cons 'and
  761.                (mapcar '(lambda (elt)
  762.                   (let ((curr (file-attributes (car elt))))
  763.                     ;; Don't compare the access time.
  764.                     (if curr (setcar (nthcdr 4 curr) 0))
  765.                     (setcar (nthcdr 4 (cdr elt)) 0)
  766.                     (equal (cdr elt) curr)))
  767.                    Info-dir-file-attributes))))
  768.       (insert Info-dir-contents)
  769.     (let ((dirs (reverse Info-directory-list))
  770.       buffers lbuffers buffer others nodes dirs-done)
  771.  
  772.       (setq Info-dir-file-attributes nil)
  773.  
  774.       ;; Search the directory list for the directory file.
  775.       (while dirs
  776.     (let ((truename (file-truename (expand-file-name (car dirs)))))
  777.       (or (member truename dirs-done)
  778.           (member (directory-file-name truename) dirs-done)
  779.           ;; Try several variants of specified name.
  780.           ;; Try upcasing, appending `.info', or both.
  781.           (let* (file
  782.              (attrs
  783.               (or
  784.                (progn (setq file (expand-file-name "dir" truename))
  785.                   (file-attributes file))
  786.                (progn (setq file (expand-file-name "DIR" truename))
  787.                   (file-attributes file))
  788.                (progn (setq file (expand-file-name "dir.info" truename))
  789.                   (file-attributes file))
  790.                (progn (setq file (expand-file-name "DIR.INFO" truename))
  791.                   (file-attributes file))
  792.                (progn (setq file (expand-file-name "localdir" truename))
  793.                   (file-attributes file))
  794.                )))
  795.         (setq dirs-done
  796.               (cons truename
  797.                 (cons (directory-file-name truename)
  798.                   dirs-done)))
  799.         (if attrs
  800.             (save-excursion
  801.               (or buffers
  802.               (message "Composing main Info directory..."))
  803.               (set-buffer (generate-new-buffer
  804.                    (if (string-match "localdir" file)
  805.                        "localdir"
  806.                      "info dir")))
  807.               (insert-file-contents file)
  808.               (if (string-match "localdir" (buffer-name))
  809.               (setq lbuffers (cons (current-buffer) lbuffers))
  810.             (setq buffers (cons (current-buffer) buffers)))
  811.               (setq Info-dir-file-attributes
  812.                 (cons (cons file attrs)
  813.                   Info-dir-file-attributes))))))
  814.       (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
  815.       (setq dirs (cdr dirs))))
  816.       
  817.       ;; ensure that the localdir files are inserted last, and reverse
  818.       ;; the list of them so that when they get pushed in, they appear
  819.       ;; in the same order they got specified in the path, from top to
  820.       ;; bottom.
  821.       (nconc buffers (nreverse lbuffers))
  822.       
  823.       (or buffers
  824.       (error "Can't find the Info directory node"))
  825.       ;; Distinguish the dir file that comes with Emacs from all the
  826.       ;; others.  Yes, that is really what this is supposed to do.
  827.       ;; If it doesn't work, fix it.
  828.       (setq buffer (car buffers)
  829.         ;; reverse it since they are pushed down from the top. the
  830.         ;; `Info-default-directory-list'/INFOPATH can be specified
  831.         ;; in natural order this way.
  832.         others (nreverse (cdr buffers)))
  833.  
  834.       ;; Insert the entire original dir file as a start; note that we've
  835.       ;; already saved its default directory to use as the default
  836.       ;; directory for the whole concatenation.
  837.       (insert-buffer buffer)
  838.  
  839.       ;; Look at each of the other buffers one by one.
  840.       (while others
  841.     (let ((other (car others))
  842.           (info-buffer (current-buffer)))
  843.       (if (string-match "localdir" (buffer-name other))
  844.           (save-excursion
  845.         (set-buffer info-buffer)
  846.         (goto-char (point-max))
  847.         (cond
  848.          ((re-search-backward "^ *\\* *Locals *: *$" nil t)
  849.           (delete-region (match-beginning 0) (match-end 0)))
  850.          ;; look for a line like |Local XEmacs packages:
  851.          ;; or mismatch on some text ...
  852.          ((re-search-backward Info-localdir-heading-regexp nil t)
  853.           ;; This is for people who underline topic headings with
  854.           ;; equal signs or dashes.
  855.           (when (save-excursion
  856.               (forward-line 1)
  857.               (beginning-of-line)
  858.               (looking-at "^[ \t]*[-=*]+"))
  859.             (forward-line 1))
  860.           (forward-line 1)
  861.           (beginning-of-line))
  862.          (t (search-backward "\^L" nil t)))
  863.         ;; Insert menu part of the file
  864.         (let* ((pt (point))
  865.                (len (length (buffer-string nil nil other))))
  866.           (insert (buffer-string nil nil other))
  867.           (goto-char (+ pt len))
  868.           (save-excursion
  869.             (goto-char pt)
  870.             (if (search-forward "* Menu:" (+ pt len) t)
  871.             (progn
  872.               (forward-line 1)
  873.               (delete-region pt (point)))))))
  874.         ;; In each, find all the menus.
  875.         (save-excursion
  876.           (set-buffer other)
  877.           (goto-char (point-min))
  878.           ;; Find each menu, and add an elt to NODES for it.
  879.           (while (re-search-forward "^\\* Menu:" nil t)
  880.         (let (beg nodename end)
  881.           (forward-line 1)
  882.           (setq beg (point))
  883.           (search-backward "\n\^_")
  884.           (search-forward "Node: ")
  885.           (setq nodename (Info-following-node-name))
  886.           (search-forward "\n\^_" nil 'move)
  887.           (beginning-of-line)
  888.           (setq end (point))
  889.           (setq nodes (cons (list nodename other beg end) nodes))))))
  890.       (setq others (cdr others))))
  891.       
  892.       ;; Add to the main menu a menu item for each other node.
  893.       (re-search-forward "^\\* Menu:" nil t)
  894.       (forward-line 1)
  895.       (let ((menu-items '("top"))
  896.         (nodes nodes)
  897.         (case-fold-search t)
  898.         (end (save-excursion (search-forward "\^_" nil t) (point))))
  899.     (while nodes
  900.       (let ((nodename (car (car nodes))))
  901.         (save-excursion
  902.           (or (member (downcase nodename) menu-items)
  903.           (re-search-forward (concat "^\\* "
  904.                          (regexp-quote nodename)
  905.                          "::")
  906.                      end t)
  907.           (progn
  908.             (insert "* " nodename "::" "\n")
  909.             (setq menu-items (cons nodename menu-items))))))
  910.       (setq nodes (cdr nodes))))
  911.       ;; Now take each node of each of the other buffers
  912.       ;; and merge it into the main buffer.
  913.       (while nodes
  914.     (let ((nodename (car (car nodes))))
  915.       (goto-char (point-min))
  916.       ;; Find the like-named node in the main buffer.
  917.       (if (re-search-forward (concat "\n\^_.*\n.*Node: "
  918.                      (regexp-quote nodename)
  919.                      "[,\n\t]")
  920.                  nil t)
  921.           (progn
  922.         (search-forward "\n\^_" nil 'move)
  923.         (beginning-of-line)
  924.         (insert "\n"))
  925.         ;; If none exists, add one.
  926.         (goto-char (point-max))
  927.         (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
  928.       ;; Merge the text from the other buffer's menu
  929.       ;; into the menu in the like-named node in the main buffer.
  930.       (apply 'insert-buffer-substring (cdr (car nodes))))
  931.     (setq nodes (cdr nodes)))
  932.       ;; Kill all the buffers we just made.
  933.       (while buffers
  934.     (kill-buffer (car buffers))
  935.     (setq buffers (cdr buffers)))
  936.       (while lbuffers
  937.     (kill-buffer (car lbuffers))
  938.     (setq lbuffers (cdr lbuffers)))
  939.       (message "Composing main Info directory...done"))
  940.     (setq Info-dir-contents (buffer-string)))
  941.   (setq default-directory Info-dir-contents-directory)
  942.   (setq buffer-file-name (caar Info-dir-file-attributes)))
  943.  
  944. (defun Info-history-add (file node point)
  945.   (if Info-keeping-history
  946.       (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
  947.          (found (assoc name Info-history)))
  948.     (if found
  949.         (setq Info-history (delq found Info-history)))
  950.     (setq Info-history (cons (list name (- point (point-min))
  951.                        (and (eq (window-buffer)
  952.                         (current-buffer))
  953.                         (- (window-start) (point-min))))
  954.                  Info-history)))))
  955.  
  956. (defun Info-file-name-only (file)
  957.   (let ((dir (file-name-directory file))
  958.     (p Info-directory-list))
  959.     (while (and p (not (equal (car p) dir)))
  960.       (setq p (cdr p)))
  961.     (if p (file-name-nondirectory file) file)))
  962.  
  963. (defun Info-read-subfile (nodepos)
  964.   (set-buffer (marker-buffer Info-tag-table-marker))
  965.   (goto-char (point-min))
  966.   (search-forward "\n\^_")
  967.   (let (lastfilepos
  968.     lastfilename)
  969.     (forward-line 2)
  970.     (catch 'foo
  971.       (while (not (looking-at "\^_"))
  972.     (if (not (eolp))
  973.         (let ((beg (point))
  974.           thisfilepos thisfilename)
  975.           (search-forward ": ")
  976.           (setq thisfilename  (buffer-substring beg (- (point) 2)))
  977.           (setq thisfilepos (read (current-buffer)))
  978.           ;; read in version 19 stops at the end of number.
  979.           ;; Advance to the next line.
  980.           (if (eolp)
  981.           (forward-line 1))
  982.           (if (> thisfilepos nodepos)
  983.           (throw 'foo t))
  984.           (setq lastfilename thisfilename)
  985.           (setq lastfilepos thisfilepos))
  986.       (throw 'foo t))))
  987.     (set-buffer (get-buffer "*info*"))
  988.     (or (equal Info-current-subfile lastfilename)
  989.     (let ((buffer-read-only nil))
  990.       (setq buffer-file-name nil)
  991.       (widen)
  992.       (erase-buffer)
  993.       (Info-insert-file-contents (Info-suffixed-file
  994.                       (expand-file-name lastfilename
  995.                             (file-name-directory
  996.                              Info-current-file)))
  997.                      t)
  998.       (set-buffer-modified-p nil)
  999.       (setq Info-current-subfile lastfilename)))
  1000.     (goto-char (point-min))
  1001.     (search-forward "\n\^_")
  1002.     (+ (- nodepos lastfilepos) (point))))
  1003.  
  1004. (defun Info-suffixed-file (name &optional name2)
  1005.   "Look for NAME with each of the `Info-suffix-list' extensions in
  1006. turn. Optional NAME2 is the name of a fallback info file to check
  1007. for; usually a downcased version of NAME."
  1008.   (let ((suff Info-suffix-list)
  1009.     (found nil)
  1010.     file file2)
  1011.     (while (and suff (not found))
  1012.       (setq file (concat name (caar suff))
  1013.         file2 (and name2 (concat name2 (caar suff))))
  1014.       (cond
  1015.        ((file-exists-p file)
  1016.     (setq found file))
  1017.        ((and file2 (file-exists-p file2))
  1018.     (setq found file2))
  1019.        (t
  1020.     (setq suff (cdr suff)))))
  1021.     (or found
  1022.     (and name (when (file-exists-p name)
  1023.             name))
  1024.     (and name2 (when (file-exists-p name2)
  1025.              name2)))))
  1026.  
  1027. (defun Info-insert-file-contents (file &optional visit)
  1028.   (setq file (expand-file-name file default-directory))
  1029.   (let ((suff Info-suffix-list))
  1030.     (while (and suff (or (<= (length file) (length (car (car suff))))
  1031.              (not (equal (substring file
  1032.                         (- (length (car (car suff)))))
  1033.                      (car (car suff))))))
  1034.       (setq suff (cdr suff)))
  1035.     (if (stringp (cdr (car suff)))
  1036.     (let ((command (if (string-match "%s" (cdr (car suff)))
  1037.                (format (cdr (car suff)) file)
  1038.              (concat (cdr (car suff)) " < " file))))
  1039.       (message "%s..." command)
  1040.       (if (eq system-type 'vax-vms)
  1041.           (call-process command nil t nil)
  1042.         (call-process shell-file-name nil t nil "-c" command))
  1043.       (message "")
  1044.       (if visit
  1045.           (progn
  1046.         (setq buffer-file-name file)
  1047.         (set-buffer-modified-p nil)
  1048.         (clear-visited-file-modtime))))
  1049.       (insert-file-contents file visit))))
  1050.  
  1051. (defun Info-select-node ()
  1052.   "Select the node that point is in, after using `g *' to select whole file."
  1053.   (interactive)
  1054.   (widen)
  1055.   (save-excursion
  1056.    ;; Find beginning of node.
  1057.    (search-backward "\n\^_")
  1058.    (forward-line 2)
  1059.    ;; Get nodename spelled as it is in the node.
  1060.    (re-search-forward "Node:[ \t]*")
  1061.    (setq Info-current-node
  1062.      (buffer-substring (point)
  1063.                (progn
  1064.                 (skip-chars-forward "^,\t\n")
  1065.                 (point))))
  1066.    (Info-set-mode-line)
  1067.    ;; Find the end of it, and narrow.
  1068.    (beginning-of-line)
  1069.    (let (active-expression)
  1070.      (narrow-to-region (point)
  1071.                (if (re-search-forward "\n[\^_\f]" nil t)
  1072.                (prog1
  1073.                 (1- (point))
  1074.                 (if (looking-at "[\n\^_\f]*execute: ")
  1075.                 (progn
  1076.                   (goto-char (match-end 0))
  1077.                   (setq active-expression
  1078.                     (read (current-buffer))))))
  1079.              (point-max)))
  1080.      (or (equal Info-footnote-tag "Note")
  1081.      (progn
  1082.        (goto-char (point-min))
  1083.        (let ((buffer-read-only nil)
  1084.          (bufmod (buffer-modified-p))
  1085.          (case-fold-search t))
  1086.          (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
  1087.            (replace-match (concat "*" Info-footnote-tag "\ ")))
  1088.          (set-buffer-modified-p bufmod))))
  1089.      (Info-reannotate-node)
  1090.      ;; XEmacs: remove v19 test
  1091.      (and Info-fontify
  1092.       (Info-fontify-node))
  1093.      (run-hooks 'Info-select-hook)
  1094.      (if Info-enable-active-nodes (eval active-expression)))))
  1095.  
  1096. (defun Info-set-mode-line ()
  1097.   (setq modeline-buffer-identification
  1098.     (list (cons modeline-buffer-id-left-extent "Info: ")
  1099.           (cons modeline-buffer-id-right-extent
  1100.             (concat
  1101.              "("
  1102.              (if Info-current-file
  1103.              (let ((name (file-name-nondirectory Info-current-file)))
  1104.                (if (string-match "\\.info$" name)
  1105.                    (substring name 0 -5)
  1106.                  name))
  1107.                "")
  1108.              ")"
  1109.              (or Info-current-node ""))))))
  1110.  
  1111. ;; Go to an info node specified with a filename-and-nodename string
  1112. ;; of the sort that is found in pointers in nodes.
  1113.  
  1114. ;;;###autoload
  1115. (defun Info-goto-node (nodename &optional no-going-back tryfile)
  1116.   "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME.
  1117. Actually, the following interpretations of NAME are tried in order:
  1118.     (FILENAME)NODENAME
  1119.     (FILENAME)     (using Top node)
  1120.     NODENAME       (in current file)
  1121.     TAGNAME        (see below)
  1122.     FILENAME       (using Top node)
  1123. where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
  1124. annotation for any node of any file.  (See `a' and `x' commands.)"
  1125.   (interactive (list (Info-read-node-name "Goto node, file or tag: ")
  1126.              nil t))
  1127.   (let (filename)
  1128.     (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
  1129.           nodename)
  1130.     (setq filename (if (= (match-beginning 1) (match-end 1))
  1131.                ""
  1132.              (substring nodename (match-beginning 2) (match-end 2)))
  1133.       nodename (substring nodename (match-beginning 3) (match-end 3)))
  1134.     (let ((trim (string-match "\\s *\\'" filename)))
  1135.       (if trim (setq filename (substring filename 0 trim))))
  1136.     (let ((trim (string-match "\\s *\\'" nodename)))
  1137.       (if trim (setq nodename (substring nodename 0 trim))))
  1138.     (Info-find-node (if (equal filename "") nil filename)
  1139.             (if (equal nodename "") "Top" nodename)
  1140.             no-going-back (and tryfile (equal filename "")))))
  1141.  
  1142. (defun Info-goto-bookmark ()
  1143.   (interactive)
  1144.   (let ((completion-ignore-case nil)
  1145.     (tag (completing-read "Goto tag: "
  1146.                   (Info-build-annotation-completions)
  1147.                   nil t nil
  1148.                   'Info-minibuffer-history)))
  1149.     (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
  1150.  
  1151. ;;;###autoload
  1152. (defun Info-visit-file ()
  1153.   "Directly visit an info file."
  1154.   (interactive)
  1155.   (let* ((insert-default-directory nil)
  1156.      (file (read-file-name "Goto Info file: " "" "")))
  1157.     (or (equal file "") (Info-find-node (expand-file-name file) "Top"))))
  1158.  
  1159. (defun Info-restore-point (&optional always)
  1160.   "Restore point to same location it had last time we were in this node."
  1161.   (interactive "p")
  1162.   (if (or Info-restoring-point always)
  1163.       (let* ((name (format "(%s)%s"
  1164.                (Info-file-name-only Info-current-file)
  1165.                Info-current-node))
  1166.          (p (assoc name Info-history)))
  1167.     (if p (Info-restore-history-entry p)))))
  1168.  
  1169. (defun Info-restore-history-entry (entry)
  1170.   (goto-char (+ (nth 1 entry) (point-min)))
  1171.   (and (nth 2 entry)
  1172.        (get-buffer-window (current-buffer))
  1173.        (set-window-start (get-buffer-window (current-buffer))
  1174.              (+ (nth 2 entry) (point-min)))))
  1175.  
  1176. (defun Info-read-node-name (prompt &optional default)
  1177.   (Info-setup-initial)
  1178.   (let* ((completion-ignore-case t)
  1179.      (nodename (completing-read prompt
  1180.                     (Info-build-node-completions)
  1181.                     nil nil nil
  1182.                     'Info-minibuffer-history)))
  1183.     (if (equal nodename "")
  1184.     (or default
  1185.         (Info-read-node-name prompt))
  1186.       nodename)))
  1187.  
  1188. (defun Info-build-annotation-completions ()
  1189.   (or Info-current-annotation-completions
  1190.       (save-excursion
  1191.     (let ((bufs (delq nil (mapcar 'get-file-buffer
  1192.                       Info-annotations-path)))
  1193.           (compl nil))
  1194.       (while bufs
  1195.         (set-buffer (car bufs))
  1196.         (goto-char (point-min))
  1197.         (while (re-search-forward "<<\\(.*\\)>>" nil t)
  1198.           (setq compl (cons (list (buffer-substring (match-beginning 1)
  1199.                             (match-end 1)))
  1200.                 compl)))
  1201.         (setq bufs (cdr bufs)))
  1202.       (setq Info-current-annotation-completions compl)))))
  1203.  
  1204. (defun Info-build-node-completions ()
  1205.   (or Info-current-file-completions
  1206.       (let ((compl (Info-build-annotation-completions)))
  1207.     (save-excursion
  1208.       (save-restriction
  1209.         (if (marker-buffer Info-tag-table-marker)
  1210.         (progn
  1211.           (set-buffer (marker-buffer Info-tag-table-marker))
  1212.           (goto-char Info-tag-table-marker)
  1213.           (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
  1214.             (setq compl
  1215.               (cons (list (buffer-substring (match-beginning 1)
  1216.                             (match-end 1)))
  1217.                 compl))))
  1218.           (widen)
  1219.           (goto-char (point-min))
  1220.           (while (search-forward "\n\^_" nil t)
  1221.         (forward-line 1)
  1222.         (let ((beg (point)))
  1223.           (forward-line 1)
  1224.           (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
  1225.                       beg t)
  1226.               (setq compl 
  1227.                 (cons (list (buffer-substring (match-beginning 1)
  1228.                               (match-end 1)))
  1229.                   compl))))))))
  1230.     (setq Info-current-file-completions compl))))
  1231.  
  1232. (defvar Info-last-search nil
  1233.   "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
  1234.  
  1235.  
  1236. ;;;###autoload
  1237. (defun Info-search (regexp)
  1238.   "Search for REGEXP, starting from point, and select node it's found in."
  1239.   (interactive "sSearch (regexp): ")
  1240.   (if (equal regexp "")
  1241.       (setq regexp Info-last-search)
  1242.     (setq Info-last-search regexp))
  1243.   (with-caps-disable-folding regexp
  1244.     (let ((found ())
  1245.           (onode Info-current-node)
  1246.           (ofile Info-current-file)
  1247.           (opoint (point))
  1248.           (osubfile Info-current-subfile))
  1249.       (save-excursion
  1250.         (save-restriction
  1251.           (widen)
  1252.           (if (null Info-current-subfile)
  1253.               (progn (re-search-forward regexp) (setq found (point)))
  1254.             (condition-case nil
  1255.                 (progn (re-search-forward regexp) (setq found (point)))
  1256.               (search-failed nil)))))
  1257.       (if (not found)                   ;can only happen in subfile case -- else would have erred
  1258.           (unwind-protect
  1259.               (let ((list ()))
  1260.                 (set-buffer (marker-buffer Info-tag-table-marker))
  1261.                 (goto-char (point-min))
  1262.                 (search-forward "\n\^_\nIndirect:")
  1263.                 (save-restriction
  1264.                   (narrow-to-region (point)
  1265.                                     (progn (search-forward "\n\^_")
  1266.                                            (1- (point))))
  1267.                   (goto-char (point-min))
  1268.                   (search-forward (concat "\n" osubfile ": "))
  1269.                   (beginning-of-line)
  1270.                   (while (not (eobp))
  1271.                     (re-search-forward "\\(^.*\\): [0-9]+$")
  1272.                     (goto-char (+ (match-end 1) 2))
  1273.                     (setq list (cons (cons (read (current-buffer))
  1274.                                            (buffer-substring (match-beginning 1)
  1275.                                                              (match-end 1)))
  1276.                                      list))
  1277.                     (goto-char (1+ (match-end 0))))
  1278.                   (setq list (nreverse list)
  1279.                         list (cdr list)))
  1280.                 (while list
  1281.                   (message "Searching subfile %s..." (cdr (car list)))
  1282.                   (Info-read-subfile (car (car list)))
  1283.                   (setq list (cdr list))
  1284.                   (goto-char (point-min))
  1285.                   (if (re-search-forward regexp nil t)
  1286.                       (setq found (point) list ())))
  1287.                 (if found
  1288.                     (message "")
  1289.                   (signal 'search-failed (list regexp))))
  1290.             (if (not found)
  1291.                 (progn (Info-read-subfile opoint)
  1292.                        (goto-char opoint)
  1293.                        (Info-select-node)))))
  1294.       (widen)
  1295.       (goto-char found)
  1296.       (Info-select-node)
  1297.       (or (and (equal onode Info-current-node)
  1298.                (equal ofile Info-current-file))
  1299.           (Info-history-add ofile onode opoint)))))
  1300.  
  1301. ;; Extract the value of the node-pointer named NAME.
  1302. ;; If there is none, use ERRORNAME in the error message; 
  1303. ;; if ERRORNAME is nil, just return nil.
  1304. (defun Info-extract-pointer (name &optional errorname)
  1305.   (save-excursion
  1306.    (goto-char (point-min))
  1307.    (forward-line 4)
  1308.    (let ((case-fold-search t))
  1309.      (if (re-search-backward (concat name ":") nil t)
  1310.      (progn
  1311.        (goto-char (match-end 0))
  1312.        (Info-following-node-name))
  1313.        (if (eq errorname t)
  1314.        nil
  1315.      (error (concat "Node has no " (capitalize (or errorname name)))))))))
  1316.  
  1317. ;; Return the node name in the buffer following point.
  1318. ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
  1319. ;; saying which chas may appear in the node name.
  1320. (defun Info-following-node-name (&optional allowedchars)
  1321.   (skip-chars-forward " \t")
  1322.   (buffer-substring
  1323.    (point)
  1324.    (progn
  1325.      (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
  1326.        (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
  1327.        (if (looking-at "(")
  1328.        (skip-chars-forward "^)")))
  1329.      (skip-chars-backward " ")
  1330.      (point))))
  1331.  
  1332. (defun Info-next (&optional n)
  1333.   "Go to the next node of this node.
  1334. A positive or negative prefix argument moves by multiple nodes."
  1335.   (interactive "p")
  1336.   (or n (setq n 1))
  1337.   (if (< n 0)
  1338.       (Info-prev (- n))
  1339.     (while (>= (setq n (1- n)) 0)
  1340.       (Info-goto-node (Info-extract-pointer "next")))))
  1341.  
  1342. (defun Info-prev (&optional n)
  1343.   "Go to the previous node of this node.
  1344. A positive or negative prefix argument moves by multiple nodes."
  1345.   (interactive "p")
  1346.   (or n (setq n 1))
  1347.   (if (< n 0)
  1348.       (Info-next (- n))
  1349.     (while (>= (setq n (1- n)) 0)
  1350.       (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
  1351.  
  1352. (defun Info-up (&optional n)
  1353.   "Go to the superior node of this node.
  1354. A positive prefix argument moves up several times."
  1355.   (interactive "p")
  1356.   (or n (setq n 1))
  1357.   (while (>= (setq n (1- n)) 0)
  1358.     (Info-goto-node (Info-extract-pointer "up")))
  1359.   (if (interactive-p) (Info-restore-point)))
  1360.  
  1361. (defun Info-last (&optional n)
  1362.   "Go back to the last node visited.
  1363. With a prefix argument, go to Nth most recently visited node.  History is
  1364. circular; after oldest node, history comes back around to most recent one.
  1365. Argument can be negative to go through the circle in the other direction.
  1366. \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
  1367.   (interactive "p")
  1368.   (or n (setq n 1))
  1369.   (or Info-history
  1370.       (error "This is the first Info node you looked at"))
  1371.   (let ((len (1+ (length Info-history))))
  1372.     (setq n (% (+ n (* len 100)) len)))
  1373.   (if (> n 0)
  1374.       (let ((entry (nth (1- n) Info-history)))
  1375.     (Info-history-add Info-current-file Info-current-node (point))
  1376.     (while (>= (setq n (1- n)) 0)
  1377.       (setq Info-history (nconc (cdr Info-history)
  1378.                     (list (car Info-history)))))
  1379.     (setq Info-history (cdr Info-history))
  1380.     (let ((Info-keeping-history nil))
  1381.       (Info-goto-node (car entry)))
  1382.     (Info-restore-history-entry entry))))
  1383.  
  1384. (defun Info-directory ()
  1385.   "Go to the Info directory node."
  1386.   (interactive)
  1387.   (Info-find-node "dir" "top"))
  1388.  
  1389. (defun Info-follow-reference (footnotename)
  1390.   "Follow cross reference named NAME to the node it refers to.
  1391. NAME may be an abbreviation of the reference name."
  1392.   (interactive
  1393.    (let ((completion-ignore-case t)
  1394.      completions default (start-point (point)) str i)
  1395.      (save-excursion
  1396.        (goto-char (point-min))
  1397.        (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
  1398.                      Info-footnote-tag)
  1399.                  nil t)
  1400.      (setq str (buffer-substring
  1401.             (match-beginning 1)
  1402.             (1- (point))))
  1403.      ;; See if this one should be the default.
  1404.      (and (null default)
  1405.           (< (match-beginning 0) start-point)
  1406.           (<= start-point (point))
  1407.           (setq default t))
  1408.      (setq i 0)
  1409.      (while (setq i (string-match "[ \n\t]+" str i))
  1410.        (setq str (concat (substring str 0 i) " "
  1411.                  (substring str (match-end 0))))
  1412.        (setq i (1+ i)))
  1413.      ;; Record as a completion and perhaps as default.
  1414.      (if (eq default t) (setq default str))
  1415.      (setq completions
  1416.            (cons (cons str nil)
  1417.              completions))))
  1418.      (if completions
  1419.      (let ((item (completing-read (if default
  1420.                       (concat "Follow reference named: ("
  1421.                           default ") ")
  1422.                     "Follow reference named: ")
  1423.                       completions nil t nil
  1424.                       'Info-minibuffer-history)))
  1425.        (if (and (string= item "") default)
  1426.            (list default)
  1427.          (list item)))
  1428.        (error "No cross-references in this node"))))
  1429.   (let (target i (str (concat "\\*" Info-footnote-tag " "
  1430.                   (regexp-quote footnotename))))
  1431.     (while (setq i (string-match " " str i))
  1432.       (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
  1433.             (substring str (1+ i))))
  1434.       (setq i (+ i 10)))
  1435.     (save-excursion
  1436.       (goto-char (point-min))
  1437.       (or (re-search-forward str nil t)
  1438.       (error "No cross-reference named %s" footnotename))
  1439.       (goto-char (match-end 1))
  1440.       (setq target
  1441.         (Info-extract-menu-node-name "Bad format cross reference" t)))
  1442.     (while (setq i (string-match "[ \t\n]+" target i))
  1443.       (setq target (concat (substring target 0 i) " "
  1444.                (substring target (match-end 0))))
  1445.       (setq i (+ i 1)))
  1446.     (Info-goto-node target)
  1447.     (setq Info-in-cross-reference t)))
  1448.  
  1449. (defun Info-next-reference (n)
  1450.   (interactive "p")
  1451.   (let ((pat (format "\\*%s[ \n\t]*\\([^:]*\\):\\|^\\* .*:\\|<<.*>>"
  1452.              Info-footnote-tag))
  1453.     (old-pt (point))
  1454.     wrapped found-nomenu)
  1455.     (while (< n 0)
  1456.       (unless (re-search-backward pat nil t)
  1457.     ;; Don't wrap more than once in a buffer where only the
  1458.     ;; menu references are found.
  1459.     (when (and wrapped (not found-nomenu))
  1460.       (goto-char old-pt)
  1461.       (error "No cross references in this node"))
  1462.     (setq wrapped t)
  1463.     (goto-char (point-max))
  1464.     (unless (re-search-backward pat nil t)
  1465.       (goto-char old-pt)
  1466.       (error "No cross references in this node")))
  1467.       (unless (save-excursion
  1468.         (goto-char (match-beginning 0))
  1469.         (when (looking-at "\\* Menu:")
  1470.           (decf n)))
  1471.     (setq found-nomenu t))
  1472.       (incf n))
  1473.     (while (> n 0)
  1474.       (or (eobp) (forward-char 1))
  1475.       (unless (re-search-forward pat nil t)
  1476.     (when (and wrapped (not found-nomenu))
  1477.       (goto-char old-pt)
  1478.       (error "No cross references in this node"))
  1479.     (setq wrapped t)
  1480.     (goto-char (point-min))
  1481.     (unless (re-search-forward pat nil t)
  1482.       (goto-char old-pt)
  1483.       (error "No cross references in this node")))
  1484.       (unless (save-excursion
  1485.         (goto-char (match-beginning 0))
  1486.         (when (looking-at "\\* Menu:")
  1487.           (incf n)))
  1488.     (setq found-nomenu t))
  1489.       (decf n))
  1490.     (when (looking-at "\\* Menu:")
  1491.       (error "No cross references in this node"))
  1492.     (goto-char (match-beginning 0))))
  1493.  
  1494. (defun Info-prev-reference (n)
  1495.   (interactive "p")
  1496.   (Info-next-reference (- n)))
  1497.  
  1498. (defun Info-extract-menu-node-name (&optional errmessage multi-line)
  1499.   (skip-chars-forward " \t\n")
  1500.   (let ((beg (point))
  1501.     str i)
  1502.     (skip-chars-forward "^:")
  1503.     (forward-char 1)
  1504.     (setq str
  1505.       (if (looking-at ":")
  1506.           (buffer-substring beg (1- (point)))
  1507.         (skip-chars-forward " \t\n")
  1508.         (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
  1509.     (while (setq i (string-match "\n" str i))
  1510.       (aset str i ?\ ))
  1511.     str))
  1512.  
  1513. (defun Info-menu (menu-item)
  1514.   "Go to node for menu item named (or abbreviated) NAME.
  1515. Completion is allowed, and the menu item point is on is the default."
  1516.   (interactive
  1517.    (let ((completions '())
  1518.      ;; If point is within a menu item, use that item as the default
  1519.      (default nil)
  1520.      (p (point))
  1521.      (last nil))
  1522.      (save-excursion
  1523.        (goto-char (point-min))
  1524.        (let ((case-fold-search t))
  1525.      (if (not (search-forward "\n* menu:" nil t))
  1526.          (error "No menu in this node")))
  1527.        (while (re-search-forward
  1528.         "\n\\* \\([^:\t\n]*\\):" nil t)
  1529.      (if (and (null default)
  1530.           (prog1 (if last (< last p) nil)
  1531.             (setq last (match-beginning 0)))
  1532.           (<= p last))
  1533.          (setq default (car (car completions))))
  1534.      (setq completions (cons (cons (buffer-substring
  1535.                      (match-beginning 1)
  1536.                      (match-end 1))
  1537.                        (match-beginning 1))
  1538.                  completions)))
  1539.        (if (and (null default) last
  1540.         (< last p)
  1541.         (<= p (progn (end-of-line) (point))))
  1542.        (setq default (car (car completions)))))
  1543.      (let ((item nil))
  1544.        (while (null item)
  1545.      (setq item (let ((completion-ignore-case t))
  1546.               (completing-read (if default
  1547.                        (format "Menu item (default %s): "
  1548.                            default)
  1549.                        "Menu item: ")
  1550.                        completions nil t nil
  1551.                        'Info-minibuffer-history)))
  1552.      ;; we rely on the fact that completing-read accepts an input
  1553.      ;; of "" even when the require-match argument is true and ""
  1554.      ;; is not a valid possibility
  1555.      (if (string= item "")
  1556.          (if default
  1557.          (setq item default)
  1558.              ;; ask again
  1559.              (setq item nil))))
  1560.        (list item))))
  1561.   ;; there is a problem here in that if several menu items have the same
  1562.   ;; name you can only go to the node of the first with this command.
  1563.   (Info-goto-node (Info-extract-menu-item menu-item) nil t))
  1564.   
  1565. (defun Info-extract-menu-item (menu-item &optional noerror)
  1566.   (save-excursion
  1567.     (goto-char (point-min))
  1568.     (if (let ((case-fold-search t))
  1569.       (search-forward "\n* menu:" nil t))
  1570.     (if (or (search-forward (concat "\n* " menu-item ":") nil t)
  1571.         (search-forward (concat "\n* " menu-item) nil t))
  1572.         (progn
  1573.           (beginning-of-line)
  1574.           (forward-char 2)
  1575.           (Info-extract-menu-node-name))
  1576.       (and (not noerror) (error "No such item in menu")))
  1577.       (and (not noerror) (error "No menu in this node")))))
  1578.  
  1579. ;; If COUNT is nil, use the last item in the menu.
  1580. (defun Info-extract-menu-counting (count &optional noerror noindex)
  1581.   (save-excursion
  1582.     (goto-char (point-min))
  1583.     (if (let ((case-fold-search t))
  1584.       (and (search-forward "\n* menu:" nil t)
  1585.            (or (not noindex)
  1586.            (not (string-match "\\<Index\\>" Info-current-node)))))
  1587.     (if (search-forward "\n* " nil t count)
  1588.         (progn
  1589.           (or count
  1590.           (while (search-forward "\n* " nil t)))
  1591.           (Info-extract-menu-node-name))
  1592.       (and (not noerror) (error "Too few items in menu")))
  1593.       (and (not noerror) (error "No menu in this node")))))
  1594.  
  1595. (defun Info-nth-menu-item (n)
  1596.   "Go to the node of the Nth menu item."
  1597.   (interactive "P")
  1598.   (or n (setq n (- last-command-char ?0)))
  1599.   (if (< n 1) (error "Index must be at least 1"))
  1600.   (Info-goto-node (Info-extract-menu-counting n) nil t))
  1601.  
  1602. (defun Info-last-menu-item ()
  1603.   "Go to the node of the tenth menu item."
  1604.   (interactive)
  1605.   (Info-goto-node (Info-extract-menu-counting nil) nil t))
  1606.  
  1607. (defun Info-top ()
  1608.   "Go to the Top node of this file."
  1609.   (interactive)
  1610.   (Info-goto-node "Top"))
  1611.  
  1612. (defun Info-end ()
  1613.   "Go to the final node in this file."
  1614.   (interactive)
  1615.   (Info-top)
  1616.   (let ((Info-keeping-history nil)
  1617.     node)
  1618.     (Info-last-menu-item)
  1619.     (while (setq node (or (Info-extract-pointer "next" t)
  1620.               (Info-extract-menu-counting nil t t)))
  1621.       (Info-goto-node node))
  1622.     (or (equal (Info-extract-pointer "up" t) "Top")
  1623.     (let ((executing-kbd-macro ""))   ; suppress messages
  1624.       (condition-case nil
  1625.           (Info-global-next 10000)
  1626.         (error nil))))))
  1627.  
  1628. (defun Info-global-next (&optional n)
  1629.   "Go to the next node in this file, traversing node structure as necessary.
  1630. This works only if the Info file is structured as a hierarchy of nodes.
  1631. A positive or negative prefix argument moves by multiple nodes."
  1632.   (interactive "p")
  1633.   (or n (setq n 1))
  1634.   (if (< n 0)
  1635.       (Info-global-prev (- n))
  1636.     (while (>= (setq n (1- n)) 0)
  1637.       (let (node)
  1638.     (cond ((and (string-match "^Top$" Info-current-node)
  1639.             (setq node (Info-extract-pointer "next" t))
  1640.             (Info-extract-menu-item node t))
  1641.            (Info-goto-node node))
  1642.           ((setq node (Info-extract-menu-counting 1 t t))
  1643.            (message "Going down...")
  1644.            (Info-goto-node node))
  1645.           (t
  1646.            (let ((Info-keeping-history Info-keeping-history)
  1647.              (orignode Info-current-node)
  1648.              (ups ""))
  1649.          (while (not (Info-extract-pointer "next" t))
  1650.            (if (and (setq node (Info-extract-pointer "up" t))
  1651.                 (not (equal node "Top")))
  1652.                (progn
  1653.              (message "Going%s..." (setq ups (concat ups " up")))
  1654.              (Info-goto-node node)
  1655.              (setq Info-keeping-history nil))
  1656.              (if orignode
  1657.              (let ((Info-keeping-history nil))
  1658.                (Info-goto-node orignode)))
  1659.              (error "Last node in file")))
  1660.          (Info-next))))))))
  1661.  
  1662. (defun Info-page-next (&optional n)
  1663.   "Scroll forward one screenful, or go to next global node.
  1664. A positive or negative prefix argument moves by multiple screenfuls."
  1665.   (interactive "p")
  1666.   (or n (setq n 1))
  1667.   (if (< n 0)
  1668.       (Info-page-prev (- n))
  1669.     (while (>= (setq n (1- n)) 0)
  1670.       (if (pos-visible-in-window-p (point-max))
  1671.       (progn
  1672.         (Info-global-next)
  1673.         (message "Node: %s" Info-current-node))
  1674.     (scroll-up)))))
  1675.  
  1676. (defun Info-scroll-next (arg)
  1677.   (interactive "P")
  1678.   (if Info-auto-advance
  1679.       (if (and (pos-visible-in-window-p (point-max))
  1680.            (not (eq Info-auto-advance t))
  1681.            (not (eq last-command this-command)))
  1682.       (message "Hit %s again to go to next node"
  1683.            (if (= last-command-char 0)
  1684.                "mouse button"
  1685.              (key-description (char-to-string last-command-char))))
  1686.     (Info-page-next)
  1687.     (setq this-command 'Info))
  1688.     (scroll-up arg)))
  1689.  
  1690. (defun Info-global-prev (&optional n)
  1691.   "Go to the previous node in this file, traversing structure as necessary.
  1692. This works only if the Info file is structured as a hierarchy of nodes.
  1693. A positive or negative prefix argument moves by multiple nodes."
  1694.   (interactive "p")
  1695.   (or n (setq n 1))
  1696.   (if (< n 0)
  1697.       (Info-global-next (- n))
  1698.     (while (>= (setq n (1- n)) 0)
  1699.       (let ((upnode (Info-extract-pointer "up" t))
  1700.         (prevnode (Info-extract-pointer "prev[ious]*" t)))
  1701.     (if (or (not prevnode)
  1702.         (equal prevnode upnode))
  1703.         (if (string-match "^Top$" Info-current-node)
  1704.         (error "First node in file")
  1705.           (message "Going up...")
  1706.           (Info-up))
  1707.       (Info-goto-node prevnode)
  1708.       (let ((downs "")
  1709.         (Info-keeping-history nil)
  1710.         node)
  1711.         (while (setq node (Info-extract-menu-counting nil t t))
  1712.           (message "Going%s..." (setq downs (concat downs " down")))
  1713.           (Info-goto-node node))))))))
  1714.  
  1715. (defun Info-page-prev (&optional n)
  1716.   "Scroll backward one screenful, or go to previous global node.
  1717. A positive or negative prefix argument moves by multiple screenfuls."
  1718.   (interactive "p")
  1719.   (or n (setq n 1))
  1720.   (if (< n 0)
  1721.       (Info-page-next (- n))
  1722.     (while (>= (setq n (1- n)) 0)
  1723.       (if (pos-visible-in-window-p (point-min))
  1724.       (progn
  1725.         (Info-global-prev)
  1726.         (message "Node: %s" Info-current-node)
  1727.         (sit-for 0)
  1728.         ;;(scroll-up 1)   ; work around bug in pos-visible-in-window-p
  1729.         ;;(scroll-down 1)
  1730.         (while (not (pos-visible-in-window-p (point-max)))
  1731.           (scroll-up)))
  1732.     (scroll-down)))))
  1733.  
  1734. (defun Info-scroll-prev (arg)
  1735.   (interactive "P")
  1736.   (if Info-auto-advance
  1737.       (if (and (pos-visible-in-window-p (point-min))
  1738.            (not (eq Info-auto-advance t))
  1739.            (not (eq last-command this-command)))
  1740.       (message "Hit %s again to go to previous node"
  1741.            (if (= last-command-char 0)
  1742.                "mouse button"
  1743.              (key-description (char-to-string last-command-char))))
  1744.     (Info-page-prev)
  1745.     (setq this-command 'Info))
  1746.     (scroll-down arg)))
  1747.  
  1748. (defun Info-index (topic)
  1749.   "Look up a string in the index for this file.
  1750. The index is defined as the first node in the top-level menu whose
  1751. name contains the word \"Index\", plus any immediately following
  1752. nodes whose names also contain the word \"Index\".
  1753. If there are no exact matches to the specified topic, this chooses
  1754. the first match which is a case-insensitive substring of a topic.
  1755. Use the `,' command to see the other matches.
  1756. Give a blank topic name to go to the Index node itself."
  1757.   (interactive "sIndex topic: ")
  1758.   (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
  1759.              (regexp-quote topic)
  1760.              "\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"))
  1761.     node)
  1762.     (message "Searching index for `%s'..." topic)
  1763.     (Info-goto-node "Top")
  1764.     (let ((case-fold-search t))
  1765.       (or (search-forward "\n* menu:" nil t)
  1766.       (error "No index"))
  1767.       (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
  1768.       (error "No index")))
  1769.     (goto-char (match-beginning 1))
  1770.     (let ((Info-keeping-history nil)
  1771.       (Info-fontify (and Info-fontify (equal topic ""))))
  1772.       (Info-goto-node (Info-extract-menu-node-name)))
  1773.     (or (equal topic "")
  1774.     (let ((matches nil)
  1775.           (exact nil)
  1776.           (Info-keeping-history nil)
  1777.           found)
  1778.       (while
  1779.           (progn
  1780.         (goto-char (point-min))
  1781.         (while (re-search-forward pattern nil t)
  1782.           (setq matches
  1783.             (cons (list (buffer-substring (match-beginning 1)
  1784.                               (match-end 1))
  1785.                     (buffer-substring (match-beginning 2)
  1786.                               (match-end 2))
  1787.                     Info-current-node
  1788.                     (string-to-int (concat "0"
  1789.                                (buffer-substring
  1790.                                 (match-beginning 3)
  1791.                                 (match-end 3)))))
  1792.                   matches)))
  1793.         (and (setq node (Info-extract-pointer "next" t))
  1794.              (string-match "\\<Index\\>" node)))
  1795.         (let ((Info-fontify nil))
  1796.           (Info-goto-node node)))
  1797.       (or matches
  1798.           (progn
  1799.         (Info-last)
  1800.         (error "No \"%s\" in index" topic)))
  1801.       ;; Here it is a feature that assoc is case-sensitive.
  1802.       (while (setq found (assoc topic matches))
  1803.         (setq exact (cons found exact)
  1804.           matches (delq found matches)))
  1805.       (setq Info-index-alternatives (nconc exact (nreverse matches))
  1806.         Info-index-first-alternative (car Info-index-alternatives))
  1807.       (Info-index-next 0)))))
  1808.  
  1809. (defun Info-index-next (num)
  1810.   "Go to the next matching index item from the last `i' command."
  1811.   (interactive "p")
  1812.   (or Info-index-alternatives
  1813.       (error "No previous `i' command in this file"))
  1814.   (while (< num 0)
  1815.     (setq num (+ num (length Info-index-alternatives))))
  1816.   (while (> num 0)
  1817.     (setq Info-index-alternatives
  1818.       (nconc (cdr Info-index-alternatives)
  1819.          (list (car Info-index-alternatives)))
  1820.       num (1- num)))
  1821.   (Info-goto-node (nth 1 (car Info-index-alternatives)))
  1822.   (if (> (nth 3 (car Info-index-alternatives)) 0)
  1823.       (forward-line (nth 3 (car Info-index-alternatives)))
  1824.     (forward-line 3)  ; don't search in headers
  1825.     (let ((name (car (car Info-index-alternatives))))
  1826.       (if (or (re-search-forward (format
  1827.                   "\\(Function\\|Command\\): %s\\( \\|$\\)"
  1828.                   (regexp-quote name)) nil t)
  1829.           (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
  1830.           (search-forward (format "`%s'" name) nil t)
  1831.           (and (string-match "\\`.*\\( (.*)\\)\\'" name)
  1832.            (search-forward
  1833.             (format "`%s'" (substring name 0 (match-beginning 1)))
  1834.             nil t))
  1835.           (search-forward name nil t))
  1836.       (beginning-of-line)
  1837.     (goto-char (point-min)))))
  1838.   (message "Found \"%s\" in %s.  %s"
  1839.        (car (car Info-index-alternatives))
  1840.        (nth 2 (car Info-index-alternatives))
  1841.        (if (cdr Info-index-alternatives)
  1842.            (if (eq (car (cdr Info-index-alternatives))
  1843.                Info-index-first-alternative)
  1844.            "(Press `,' to repeat)"
  1845.          (format "(Press `,' for %d more)"
  1846.              (- (1- (length Info-index-alternatives))
  1847.                 (length (memq Info-index-first-alternative
  1848.                       (cdr Info-index-alternatives))))))
  1849.          "(Only match)")))
  1850.  
  1851.  
  1852. ;;;###autoload
  1853. (defun Info-emacs-command (command)
  1854.   "Look up an Emacs command in the Emacs manual in the Info system.
  1855. This command is designed to be used whether you are already in Info or not."
  1856.   (interactive "CLook up command in Emacs manual: ")
  1857.   (save-window-excursion
  1858.     (info)
  1859.     (Info-find-node Info-emacs-info-file-name "Top")
  1860.     (Info-index (symbol-name command)))
  1861.   (pop-to-buffer "*info*"))
  1862.  
  1863.  
  1864. ;;;###autoload
  1865. (defun Info-goto-emacs-command-node (key)
  1866.   "Look up an Emacs command in the Emacs manual in the Info system.
  1867. This command is designed to be used whether you are already in Info or not."
  1868.   (interactive "CLook up command in Emacs manual: ")
  1869.   (Info-emacs-command key))
  1870.  
  1871. ;;;###autoload
  1872. (defun Info-goto-emacs-key-command-node (key)
  1873.   "Look up an Emacs key sequence in the Emacs manual in the Info system.
  1874. This command is designed to be used whether you are already in Info or not."
  1875.   (interactive "kLook up key in Emacs manual: ")
  1876.   (let ((command (key-binding key)))
  1877.     (cond ((eq command 'keyboard-quit)
  1878.        (keyboard-quit))
  1879.       ((null command)
  1880.        (error "%s is undefined" (key-description key)))
  1881.       ((and (interactive-p) (eq command 'execute-extended-command))
  1882.        (call-interactively 'Info-goto-emacs-command-node))
  1883.       (t
  1884.        (Info-goto-emacs-command-node command)))))
  1885.  
  1886. ;;;###autoload
  1887. (defun Info-emacs-key (key)
  1888.   "Look up an Emacs key sequence in the Emacs manual in the Info system.
  1889. This command is designed to be used whether you are already in Info or not."
  1890.   (interactive "kLook up key in Emacs manual: ")
  1891.   (cond ((eq (key-binding key) 'keyboard-quit)
  1892.      (keyboard-quit))
  1893.     ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
  1894.      (call-interactively 'Info-goto-emacs-command-node))
  1895.     (t
  1896.      (save-window-excursion
  1897.        (info)
  1898.        (Info-find-node Info-emacs-info-file-name "Top")
  1899.        (setq key (key-description key))
  1900.        (let (p)
  1901.          (if (setq p (string-match "[@{}]" key))
  1902.          (setq key (concat (substring key 0 p) "@" (substring key p))))
  1903.          (if (string-match "^ESC " key)
  1904.          (setq key (concat "M-" (substring key 4))))
  1905.          (if (string-match "^M-C-" key)
  1906.          (setq key (concat "C-M-" (substring key 4)))))
  1907.        (Info-index key))
  1908.      (pop-to-buffer "*info*"))))
  1909.  
  1910. ;;;###autoload
  1911. (defun Info-elisp-ref (func)
  1912.   "Look up an Emacs Lisp function in the Elisp manual in the Info system.
  1913. This command is designed to be used whether you are already in Info or not."
  1914.   (interactive (let ((fn (function-at-point))
  1915.              (enable-recursive-minibuffers t)         
  1916.              val)
  1917.          (setq val (completing-read
  1918.                 (format "Look up Emacs Lisp function%s: "
  1919.                     (if fn
  1920.                     (format " (default %s)" fn)
  1921.                       ""))
  1922.                 obarray 'fboundp t))
  1923.          (list (if (equal val "")
  1924.                fn (intern val)))))
  1925.   (save-window-excursion
  1926.     (info)
  1927.     (condition-case nil
  1928.     (Info-find-node "lispref" "Top")
  1929.       (error (Info-find-node "elisp" "Top")))
  1930.     (Info-index (symbol-name func)))
  1931.   (pop-to-buffer "*info*"))
  1932.  
  1933. (defun Info-reannotate-node ()
  1934.   (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
  1935.     (if bufs
  1936.     (let ((ibuf (current-buffer))
  1937.           (file (concat "\\(" (regexp-quote
  1938.                  (file-name-nondirectory Info-current-file))
  1939.                 "\\|" (regexp-quote Info-current-file) "\\)"))
  1940.           (node (regexp-quote Info-current-node))
  1941.           (savept (point)))
  1942.       (goto-char (point-min))
  1943.       (if (search-forward "\n------ NOTE:\n" nil t)
  1944.           (let ((buffer-read-only nil)
  1945.             (bufmod (buffer-modified-p))
  1946.             top)
  1947.         (setq savept (copy-marker savept))
  1948.         (goto-char (point-min))
  1949.         (while (search-forward "\n------ NOTE:" nil t)
  1950.           (setq top (1+ (match-beginning 0)))
  1951.           (if (search-forward "\n------\n" nil t)
  1952.               (delete-region top (point)))
  1953.           (backward-char 1))
  1954.         (set-buffer-modified-p bufmod)))
  1955.       (save-excursion
  1956.         (while bufs
  1957.           (set-buffer (car bufs))
  1958.           (goto-char (point-min))
  1959.           (while (re-search-forward
  1960.               (format
  1961.                "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
  1962.                file node)
  1963.               nil t)
  1964.         (let ((line (string-to-int
  1965.                  (buffer-substring (match-beginning 2)
  1966.                            (match-end 2))))
  1967.               (top (point))
  1968.               bot)
  1969.           (search-forward "\n------\n" nil t)
  1970.           (setq bot (point))
  1971.           (save-excursion
  1972.             (set-buffer ibuf)
  1973.             (if (integerp savept) (setq savept (copy-marker savept)))
  1974.             (if (= line 0)
  1975.             (goto-char (point-max))
  1976.               (goto-char (point-min))
  1977.               (forward-line line))
  1978.             (let ((buffer-read-only nil)
  1979.               (bufmod (buffer-modified-p)))
  1980.               (insert "------ NOTE:\n")
  1981.               (insert-buffer-substring (car bufs) top bot)
  1982.               (set-buffer-modified-p bufmod)))))
  1983.           (setq bufs (cdr bufs))))
  1984.       (goto-char savept)))))
  1985.  
  1986. (defvar Info-annotate-map nil
  1987.   "Local keymap used within `a' command of Info.")
  1988. (if Info-annotate-map
  1989.     nil
  1990.   ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
  1991.   (setq Info-annotate-map (copy-keymap text-mode-map))
  1992.   (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
  1993.  
  1994. (defun Info-annotate-mode ()
  1995.   "Major mode for adding an annotation to an Info node.
  1996. Like text mode with the addition of Info-cease-annotate
  1997. which returns to Info mode for browsing.
  1998. \\{Info-annotate-map}")
  1999.  
  2000. (defun Info-annotate (arg)
  2001.   "Add a personal annotation to the current Info node.
  2002.  Only you will be able to see this annotation.  Annotations are stored
  2003. in the file \"~/.xemacs/info.notes\" by default.  If point is inside
  2004. an existing annotation, edit that annotation.  A prefix argument
  2005. specifies which annotations file (from `Info-annotations-path') is to
  2006. be edited; default is 1."
  2007.   (interactive "p")
  2008.   (setq arg (1- arg))
  2009.   (if (or (< arg 0) (not (nth arg Info-annotations-path)))
  2010.       (if (= arg 0)
  2011.       (setq Info-annotations-path
  2012.         (list (read-file-name
  2013.                "Annotations file: " "~/" "~/.infonotes")))
  2014.     (error "File number must be in the range from 1 to %d"
  2015.            (length Info-annotations-path))))
  2016.   (let ((which nil)
  2017.     (file (file-name-nondirectory Info-current-file))
  2018.     (d Info-directory-list)
  2019.     where pt)
  2020.     (while (and d (not (equal (expand-file-name file (car d))
  2021.                   Info-current-file)))
  2022.       (setq d (cdr d)))
  2023.     (or d (setq file Info-current-file))
  2024.     (if (and (save-excursion
  2025.            (goto-char (min (point-max) (+ (point) 13)))
  2026.            (and (search-backward "------ NOTE:\n" nil t)
  2027.             (setq pt (match-end 0))
  2028.             (search-forward "\n------\n" nil t)))
  2029.          (< (point) (match-end 0)))
  2030.     (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
  2031.                 (regexp-quote file)
  2032.                 (regexp-quote Info-current-node)
  2033.                 (regexp-quote
  2034.                  (buffer-substring pt (match-beginning 0))))
  2035.           where (max (- (point) pt) 0)))
  2036.     (let ((node Info-current-node)
  2037.       (line (if (looking-at "[ \n]*\\'") 0
  2038.           (count-lines (point-min) (point)))))
  2039.       (or which
  2040.       (let ((buffer-read-only nil)
  2041.         (bufmod (buffer-modified-p)))
  2042.         (beginning-of-line)
  2043.         (if (bobp) (goto-char (point-max)))
  2044.         (insert "------ NOTE:\n------\n")
  2045.         (backward-char 20)
  2046.         (set-buffer-modified-p bufmod)))
  2047.       ;; (setq Info-window-start (window-start))
  2048.       (setq Info-window-configuration (current-window-configuration))
  2049.       (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
  2050.       (use-local-map Info-annotate-map)
  2051.       (setq major-mode 'Info-annotate-mode)
  2052.       (setq mode-name "Info Annotate")
  2053.       (if which
  2054.       (if (save-excursion
  2055.         (goto-char (point-min))
  2056.         (re-search-forward which nil t))
  2057.           (progn
  2058.         (goto-char (match-beginning 0))
  2059.         (forward-line 1)
  2060.         (forward-char where)))
  2061.     (let ((bufmod (buffer-modified-p)))
  2062.       (goto-char (point-max))
  2063.       (insert (format "\n------ File: %s  Node: %s  Line: %d\n"
  2064.               file node line))
  2065.       (setq pt (point))
  2066.       (insert "\n------\n"
  2067.           "\nPress C-c C-c to save and return to Info.\n")
  2068.       (goto-char pt)
  2069.       (set-buffer-modified-p bufmod))))))
  2070.  
  2071. (defun Info-cease-annotate ()
  2072.   (interactive)
  2073.   (let ((bufmod (buffer-modified-p)))
  2074.     (while (save-excursion
  2075.          (goto-char (point-min))
  2076.          (re-search-forward "\n\n?Press .* to save and return to Info.\n"
  2077.                 nil t))
  2078.       (delete-region (1+ (match-beginning 0)) (match-end 0)))
  2079.     (while (save-excursion
  2080.          (goto-char (point-min))
  2081.          (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
  2082.                 nil t))
  2083.       (delete-region (match-beginning 0) (match-end 0)))
  2084.     (set-buffer-modified-p bufmod))
  2085.   (save-buffer)
  2086.   (fundamental-mode)
  2087.   (bury-buffer)
  2088.   (or (one-window-p) (delete-window))
  2089.   (info)
  2090.   (setq Info-current-annotation-completions nil)
  2091.   (set-window-configuration Info-window-configuration)
  2092.   (Info-reannotate-node))
  2093.  
  2094. (defun Info-bookmark (arg tag)
  2095.   (interactive "p\nsBookmark name: ")
  2096.   (Info-annotate arg)
  2097.   (if (or (string-match "^\"\\(.*\\)\"$" tag)
  2098.       (string-match "^<<\\(.*\\)>>$" tag))
  2099.       (setq tag (substring tag (match-beginning 1) (match-end 1))))
  2100.   (let ((pt (point)))
  2101.     (search-forward "\n------\n")
  2102.     (let ((end (- (point) 8)))
  2103.       (goto-char pt)
  2104.       (if (re-search-forward "<<[^>\n]*>>" nil t)
  2105.       (delete-region (match-beginning 0) (match-end 0))
  2106.     (goto-char end))
  2107.       (or (equal tag "")
  2108.       (insert "<<" tag ">>"))))
  2109.   (Info-cease-annotate))
  2110.  
  2111. (defun Info-exit ()
  2112.   "Exit Info by selecting some other buffer."
  2113.   (interactive)
  2114.   (if Info-standalone
  2115.       (save-buffers-kill-emacs)
  2116.     (bury-buffer (current-buffer))
  2117.     (if (and (featurep 'toolbar)
  2118.          (eq toolbar-info-frame (selected-frame)))
  2119.     (condition-case ()
  2120.         (delete-frame toolbar-info-frame)
  2121.       (error (bury-buffer)))
  2122.       (switch-to-buffer (other-buffer (current-buffer))))))
  2123.  
  2124. (defun Info-undefined ()
  2125.   "Make command be undefined in Info."
  2126.   (interactive)
  2127.   (ding))
  2128.  
  2129. (defun Info-help ()
  2130.   "Enter the Info tutorial."
  2131.   (interactive)
  2132.   (delete-other-windows)
  2133.   (Info-find-node "info"
  2134.           (if (< (window-height) 23)
  2135.               "Help-Small-Screen"
  2136.             "Help")))
  2137.  
  2138. (defun Info-summary ()
  2139.   "Display a brief summary of all Info commands."
  2140.   (interactive)
  2141.   (save-window-excursion
  2142.     (switch-to-buffer "*Help*")
  2143.     (erase-buffer)
  2144.     (insert (documentation 'Info-mode))
  2145.     (goto-char (point-min))
  2146.     (let (flag)
  2147.       (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
  2148.             (message (if flag "Type Space to see more"
  2149.                    "Type Space to return to Info"))
  2150.             (let ((e (next-command-event)))
  2151.               (if (/= ?\  (event-to-character e))
  2152.               (progn (setq unread-command-event e) nil)
  2153.             flag)))
  2154.     (scroll-up)))
  2155.     (message "")
  2156.     (bury-buffer "*Help*")))
  2157.  
  2158. (defun Info-get-token (pos start all &optional errorstring)
  2159.   "Return the token around POS,
  2160. POS must be somewhere inside the token
  2161. START is a regular expression which will match the
  2162.     beginning of the tokens delimited string
  2163. ALL is a regular expression with a single
  2164.     parenthized subpattern which is the token to be
  2165.     returned. E.g. '{\(.*\)}' would return any string
  2166.     enclosed in braces around POS.
  2167. SIG optional fourth argument, controls action on no match
  2168.     nil: return nil
  2169.     t: beep
  2170.     a string: signal an error, using that string."
  2171.   (save-excursion
  2172.     (goto-char (point-min))
  2173.     (re-search-backward "\\`")  ; Bug fix due to Nicholas J. Foskett.
  2174.     (goto-char pos)
  2175.     (re-search-backward start (max (point-min) (- pos 200)) 'yes)
  2176.     (let (found)
  2177.       (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
  2178.           (not (setq found (and (<= (match-beginning 0) pos)
  2179.                     (> (match-end 0) pos))))))
  2180.       (if (and found (<= (match-beginning 0) pos)
  2181.            (> (match-end 0) pos))
  2182.       (buffer-substring (match-beginning 1) (match-end 1))
  2183.     (cond ((null errorstring)
  2184.            nil)
  2185.           ((eq errorstring t)
  2186.            (beep)
  2187.            nil)
  2188.           (t
  2189.            (error "No %s around position %d" errorstring pos)))))))
  2190.  
  2191. (defun Info-follow-clicked-node (event)
  2192.   "Follow a node reference near clicked point.  Like M, F, N, P or U command.
  2193. At end of the node's text, moves to the next node."
  2194.   (interactive "@e")
  2195.   (or (and (event-point event)
  2196.        (Info-follow-nearest-node
  2197.         (max (progn
  2198.            (select-window (event-window event))
  2199.            (event-point event))
  2200.          (1+ (point-min)))))
  2201.       (error "click on a cross-reference to follow")))
  2202.  
  2203. (defun Info-maybe-follow-clicked-node (event &optional click-count)
  2204.   "Follow a node reference (if any) near clicked point.
  2205. Like M, F, N, P or U command.  At end of the node's text, moves to the
  2206. next node.  No error is given if there is no node to follow."
  2207.   (interactive "@e")
  2208.   (and Info-button1-follows-hyperlink
  2209.        (event-point event)
  2210.        (Info-follow-nearest-node
  2211.     (max (progn
  2212.            (select-window (event-window event))
  2213.            (event-point event))
  2214.          (1+ (point-min))))))
  2215.  
  2216. (defun Info-find-nearest-node (point)
  2217.   (let (node)
  2218.     (cond
  2219.      ((= point (point-min)) nil)   ; don't trigger on accidental RET.
  2220.      ((setq node (Info-get-token point
  2221.                  (format "\\*%s[ \n]" Info-footnote-tag)
  2222.                  (format "\\*%s[ \n]\\([^:]*\\):"
  2223.                      Info-footnote-tag)))
  2224.       (list "Following cross-reference %s..."
  2225.         (list 'Info-follow-reference node)))
  2226.      ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\)::"))
  2227.       (list "Selecting menu item %s..."
  2228.         (list 'Info-goto-node node nil t)))
  2229.      ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\):"))
  2230.       (list "Selecting menu item %s..."
  2231.         (list 'Info-menu node)))
  2232.      ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
  2233.       (list "Going up..."
  2234.         (list 'Info-goto-node node)))
  2235.      ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
  2236.       (list "Next node..."
  2237.         (list 'Info-goto-node node)))
  2238.      ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
  2239.       (list "Top node..."
  2240.         (list 'Info-goto-node "Top")))
  2241.      ((setq node (Info-get-token point "Prev[ious]*: "
  2242.                  "Prev[ious]*: \\([^,\n\t]*\\)"))
  2243.       (list "Previous node..."
  2244.         (list 'Info-goto-node node)))
  2245.      ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
  2246.       (list "Reselecting %s..."
  2247.         (list 'Info-goto-node node)))
  2248.      ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
  2249.       (if Info-in-cross-reference
  2250.       (list "Back to last node..."
  2251.         '(Info-last))
  2252.     (list "Next node..."
  2253.           '(Info-global-next)))))
  2254.     ))
  2255.  
  2256. (defun Info-follow-nearest-node (point)
  2257.   "Follow a node reference near point.  Like M, F, N, P or U command.
  2258. At end of the node's text, moves to the next node."
  2259.   (interactive "d")
  2260.   (let ((data (Info-find-nearest-node point)))
  2261.     (if (null data)
  2262.     nil
  2263.       (let ((msg (format (car data) (nth 1 (nth 1 data)))))
  2264.     (message "%s" msg)
  2265.     (eval (nth 1 data))
  2266.     (message "%sdone" msg))
  2267.       t)))
  2268.  
  2269. (defun Info-indicated-node (event)
  2270.   (condition-case ()
  2271.       (save-excursion
  2272.     (cond ((eventp event)
  2273.            (set-buffer (event-buffer event))
  2274.            (setq event (event-point event))))
  2275.     (let* ((data (Info-find-nearest-node event))
  2276.            (name (nth 1 (nth 1 data))))
  2277.       (and name (nth 1 data))))
  2278.     (error nil)))
  2279.  
  2280. (defun Info-mouse-track-double-click-hook (event click-count)
  2281.   "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
  2282.   (if (/= click-count 2)
  2283.       ;; Return nil so any other hooks are performed.
  2284.       nil
  2285.       (let* ((x (event-x-pixel event))
  2286.          (y (event-y-pixel event))
  2287.          (w (window-pixel-width (event-window event)))
  2288.          (h (window-pixel-height (event-window event)))
  2289.          (w/3 (/ w 3))
  2290.          (w/2 (/ w 2))
  2291.          (h/4 (/ h 4)))
  2292.     (cond
  2293.       ;; In the top 1/4 and inside the middle 1/3
  2294.       ((and (<= y h/4)
  2295.         (and (>= x w/3) (<= x (+ w/3 w/3))))
  2296.        (Info-up)
  2297.        t)
  2298.       ;; In the bottom 1/4 and inside the middle 1/3
  2299.       ((and (>= y (+ h/4 h/4 h/4))
  2300.         (and (>= x w/3) (<= x (+ w/3 w/3))))
  2301.        (Info-nth-menu-item 1)
  2302.        t)
  2303.       ;; In the lower 3/4 and the right 1/2
  2304.       ;; OR in the upper 1/4 and the right 1/3
  2305.       ((or (and (>= y h/4) (>= x w/2))
  2306.            (and (< y h/4) (>= x (+ w/3 w/3))))
  2307.        (Info-next)
  2308.        t)
  2309.       ;; In the lower 3/4 and the left 1/2
  2310.       ;; OR in the upper 1/4 and the left 1/3
  2311.       ((or (and (>= y h/4) (< x w/2))
  2312.            (and (< y h/4) (<= x w/3)))
  2313.        (Info-prev)
  2314.        t)
  2315.       ;; This shouldn't happen.
  2316.       (t
  2317.        (error "event out of bounds: %s %s" x y))))))
  2318.  
  2319. (defvar Info-mode-map nil
  2320.   "Keymap containing Info commands.")
  2321. (if Info-mode-map
  2322.     nil
  2323.   (setq Info-mode-map (make-sparse-keymap))
  2324.   (suppress-keymap Info-mode-map)
  2325.   (define-key Info-mode-map "." 'beginning-of-buffer)
  2326.   (define-key Info-mode-map " " 'Info-scroll-next)
  2327.   (define-key Info-mode-map "1" 'Info-nth-menu-item)
  2328.   (define-key Info-mode-map "2" 'Info-nth-menu-item)
  2329.   (define-key Info-mode-map "3" 'Info-nth-menu-item)
  2330.   (define-key Info-mode-map "4" 'Info-nth-menu-item)
  2331.   (define-key Info-mode-map "5" 'Info-nth-menu-item)
  2332.   (define-key Info-mode-map "6" 'Info-nth-menu-item)
  2333.   (define-key Info-mode-map "7" 'Info-nth-menu-item)
  2334.   (define-key Info-mode-map "8" 'Info-nth-menu-item)
  2335.   (define-key Info-mode-map "9" 'Info-nth-menu-item)
  2336.   (define-key Info-mode-map "0" 'Info-last-menu-item)
  2337.   (define-key Info-mode-map "?" 'Info-summary)
  2338.   (define-key Info-mode-map "a" 'Info-annotate)
  2339.   (define-key Info-mode-map "b" 'beginning-of-buffer)
  2340.   (define-key Info-mode-map "d" 'Info-directory)
  2341.   (define-key Info-mode-map "e" 'Info-edit)
  2342.   (define-key Info-mode-map "f" 'Info-follow-reference)
  2343.   (define-key Info-mode-map "g" 'Info-goto-node)
  2344.   (define-key Info-mode-map "h" 'Info-help)
  2345.   (define-key Info-mode-map "i" 'Info-index)
  2346.   (define-key Info-mode-map "j" 'Info-goto-bookmark)
  2347.   (define-key Info-mode-map "k" 'Info-emacs-key)
  2348.   (define-key Info-mode-map "l" 'Info-last)
  2349.   (define-key Info-mode-map "m" 'Info-menu)
  2350.   (define-key Info-mode-map "n" 'Info-next)
  2351.   (define-key Info-mode-map "p" 'Info-prev)
  2352.   (define-key Info-mode-map "q" 'Info-exit)
  2353.   (define-key Info-mode-map "r" 'Info-follow-reference)
  2354.   (define-key Info-mode-map "s" 'Info-search)
  2355.   (define-key Info-mode-map "t" 'Info-top)
  2356.   (define-key Info-mode-map "u" 'Info-up)
  2357.   (define-key Info-mode-map "v" 'Info-visit-file)
  2358.   (define-key Info-mode-map "x" 'Info-bookmark)
  2359.   (define-key Info-mode-map "<" 'Info-top)
  2360.   (define-key Info-mode-map ">" 'Info-end)
  2361.   (define-key Info-mode-map "[" 'Info-global-prev)
  2362.   (define-key Info-mode-map "]" 'Info-global-next)
  2363.   (define-key Info-mode-map "{" 'Info-page-prev)
  2364.   (define-key Info-mode-map "}" 'Info-page-next)
  2365.   (define-key Info-mode-map "=" 'Info-restore-point)
  2366.   (define-key Info-mode-map "!" 'Info-select-node)
  2367.   (define-key Info-mode-map "@" 'Info-follow-nearest-node)
  2368.   (define-key Info-mode-map "," 'Info-index-next)
  2369.   (define-key Info-mode-map "*" 'Info-elisp-ref)
  2370.   (define-key Info-mode-map [tab] 'Info-next-reference)
  2371.   (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
  2372.   (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
  2373.   (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
  2374.   ;; XEmacs addition
  2375.   (define-key Info-mode-map 'backspace 'Info-scroll-prev)
  2376.   (define-key Info-mode-map 'delete 'Info-scroll-prev)
  2377.   (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
  2378.   (define-key Info-mode-map 'button3 'Info-select-node-menu))
  2379.  
  2380.  
  2381. ;; Info mode is suitable only for specially formatted data.
  2382. (put 'info-mode 'mode-class 'special)
  2383.  
  2384. (defun Info-mode ()
  2385.   "Info mode is for browsing through the Info documentation tree.
  2386. Documentation in Info is divided into \"nodes\", each of which
  2387. discusses one topic and contains references to other nodes
  2388. which discuss related topics.  Info has commands to follow
  2389. the references and show you other nodes.
  2390.  
  2391. h    Invoke the Info tutorial.
  2392. q    Quit Info: return to the previously selected file or buffer.
  2393.  
  2394. Selecting other nodes:
  2395. n    Move to the \"next\" node of this node.
  2396. p    Move to the \"previous\" node of this node.
  2397. m    Pick menu item specified by name (or abbreviation).
  2398. 1-9, 0    Pick first..ninth, last item in node's menu.
  2399.     Menu items select nodes that are \"subsections\" of this node.
  2400. u    Move \"up\" from this node (i.e., from a subsection to a section).
  2401. f or r    Follow a cross reference by name (or abbrev).  Type `l' to get back.
  2402. RET     Follow cross reference or menu item indicated by cursor.
  2403. i    Look up a topic in this file's Index and move to that node.
  2404. ,    (comma) Move to the next match from a previous `i' command.
  2405. l    (letter L) Move back to the last node you were in.
  2406.  
  2407. Moving within a node:
  2408. Space    Scroll forward a full screen.   DEL       Scroll backward.
  2409. b    Go to beginning of node.        Meta->    Go to end of node.
  2410. TAB    Go to next cross-reference.     Meta-TAB  Go to previous ref.
  2411.  
  2412. Mouse commands:
  2413. Left Button    Set point.
  2414. Middle Button    Click on a highlighted node reference to go to it.
  2415. Right Button    Pop up a menu of applicable Info commands.
  2416.  
  2417. Advanced commands:
  2418. g    Move to node, file, or annotation tag specified by name.
  2419.     Examples:  `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
  2420. v    Move to file, with filename completion.
  2421. k    Look up a key sequence in Emacs manual (also C-h C-k at any time).
  2422. *    Look up a function name in Emacs Lisp manual (also C-h C-f).
  2423. d    Go to the main directory of Info files.
  2424. < or t    Go to Top (first) node of this file.
  2425. >    Go to last node in this file.
  2426. \[    Go to previous node, treating file as one linear document.
  2427. \]    Go to next node, treating file as one linear document.
  2428. {    Scroll backward, or go to previous node if at top.
  2429. }    Scroll forward, or go to next node if at bottom.
  2430. =    Restore cursor position from last time in this node.
  2431. a    Add a private note (annotation) to the current node.
  2432. x, j    Add, jump to a bookmark (annotation tag).
  2433. s    Search this Info file for a node containing the specified regexp.
  2434. e    Edit the contents of the current node."
  2435.   (kill-all-local-variables)
  2436.   (setq major-mode 'Info-mode)
  2437.   (setq mode-name "Info")
  2438.   (use-local-map Info-mode-map)
  2439.   (set-syntax-table text-mode-syntax-table)
  2440.   (setq local-abbrev-table text-mode-abbrev-table)
  2441.   (setq case-fold-search t)
  2442.   (setq buffer-read-only t)
  2443. ;  (setq buffer-mouse-map Info-mode-mouse-map)
  2444.   (make-local-variable 'Info-current-file)
  2445.   (make-local-variable 'Info-current-subfile)
  2446.   (make-local-variable 'Info-current-node)
  2447.   (make-local-variable 'Info-tag-table-marker)
  2448.   (make-local-variable 'Info-current-file-completions)
  2449.   (make-local-variable 'Info-current-annotation-completions)
  2450.   (make-local-variable 'Info-index-alternatives)
  2451.   (make-local-variable 'Info-history)
  2452.   ;; Faces are now defined by `defface'...
  2453.   (make-local-variable 'mouse-track-click-hook)
  2454.   (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
  2455.   (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
  2456.   ;; #### The console-on-window-system-p check is to allow this to
  2457.   ;; work on tty's.  The real problem here is that featurep really
  2458.   ;; needs to have some device/console domain knowledge added to it.
  2459.   (if (and (featurep 'toolbar)
  2460.        (console-on-window-system-p)
  2461.        (not Info-inhibit-toolbar))
  2462.       (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
  2463.   (if (featurep 'menubar)
  2464.       (progn
  2465.     ;; make a local copy of the menubar, so our modes don't
  2466.     ;; change the global menubar
  2467.     (set-buffer-menubar current-menubar)
  2468.     (add-submenu nil '("Info"
  2469.                :filter Info-menu-filter))))
  2470.   (run-hooks 'Info-mode-hook)
  2471.   (Info-set-mode-line))
  2472.  
  2473. (defvar Info-edit-map nil
  2474.   "Local keymap used within `e' command of Info.")
  2475. (if Info-edit-map
  2476.     nil
  2477.   ;; XEmacs: remove FSF stuff
  2478.   (setq Info-edit-map (make-sparse-keymap))
  2479.   (set-keymap-name Info-edit-map 'Info-edit-map)
  2480.   (set-keymap-parents Info-edit-map (list text-mode-map))
  2481.   (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
  2482.  
  2483. ;; Info-edit mode is suitable only for specially formatted data.
  2484. (put 'info-edit-mode 'mode-class 'special)
  2485.  
  2486. (defun Info-edit-mode ()
  2487.   "Major mode for editing the contents of an Info node.
  2488. Like text mode with the addition of `Info-cease-edit'
  2489. which returns to Info mode for browsing.
  2490. \\{Info-edit-map}"
  2491.   )
  2492.  
  2493. (defun Info-edit ()
  2494.   "Edit the contents of this Info node.
  2495. Allowed only if variable `Info-enable-edit' is non-nil."
  2496.   (interactive)
  2497.   (or Info-enable-edit
  2498.       (error "Editing info nodes is not enabled"))
  2499.   (use-local-map Info-edit-map)
  2500.   (setq major-mode 'Info-edit-mode)
  2501.   (setq mode-name "Info Edit")
  2502.   (kill-local-variable 'modeline-buffer-identification)
  2503.   (setq buffer-read-only nil)
  2504.   ;; Make mode line update.
  2505.   (set-buffer-modified-p (buffer-modified-p))
  2506.   (message (substitute-command-keys
  2507.          "Editing: Type \\[Info-cease-edit] to return to info")))
  2508.  
  2509. (defun Info-cease-edit ()
  2510.   "Finish editing Info node; switch back to Info proper."
  2511.   (interactive)
  2512.   ;; Do this first, so nothing has changed if user C-g's at query.
  2513.   (and (buffer-modified-p)
  2514.        (y-or-n-p-maybe-dialog-box "Save the file? ")
  2515.        (save-buffer))
  2516.   (use-local-map Info-mode-map)
  2517.   (setq major-mode 'Info-mode)
  2518.   (setq mode-name "Info")
  2519.   (Info-set-mode-line)
  2520.   (setq buffer-read-only t)
  2521.   ;; Make mode line update.
  2522.   (set-buffer-modified-p (buffer-modified-p))
  2523.   (and (marker-position Info-tag-table-marker)
  2524.        (buffer-modified-p)
  2525.        (message "Tags may have changed.  Use Info-tagify if necessary")))
  2526.  
  2527. (defun Info-find-emacs-command-nodes (command)
  2528.   "Return a list of locations documenting COMMAND in the XEmacs Info manual.
  2529. The locations are of the format used in Info-history, i.e.
  2530. \(FILENAME NODENAME BUFFERPOS\)."
  2531.   (let ((where '())
  2532.     (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
  2533.               ":\\s *\\(.*\\)\\.$")))
  2534.     (save-excursion
  2535.       (Info-find-node "XEmacs" "Command Index")
  2536.       ;; Take the index node off the Info history.
  2537.       ;; ??? says this isn't safe someplace else... hmmm.
  2538.       (setq Info-history (cdr Info-history))
  2539.       (goto-char (point-max))
  2540.       (while (re-search-backward cmd-desc nil t)
  2541.       (setq where (cons (list Info-current-file
  2542.                   (buffer-substring
  2543.                    (match-beginning 1)
  2544.                    (match-end 1))
  2545.                   0)
  2546.                 where)))
  2547.       where)))
  2548.  
  2549. ;;; fontification and mousability for info
  2550.  
  2551. (defun Info-highlight-region (start end face)
  2552.   (let ((extent nil)
  2553.     (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
  2554.     (if splitp
  2555.     (save-excursion
  2556.       (setq extent (make-extent start (progn (goto-char start)
  2557.                          (end-of-line)
  2558.                          (point))))
  2559.       (set-extent-face extent face)
  2560.       (set-extent-property extent 'info t)
  2561.       (set-extent-property extent 'highlight t)
  2562.       (skip-chars-forward "\n\t ")
  2563.       (setq extent (make-extent (point) end)))
  2564.       (setq extent (make-extent start end)))
  2565.     (set-extent-face extent face)
  2566.     (set-extent-property extent 'info t)
  2567.     (set-extent-property extent 'highlight t)))
  2568.  
  2569. (defun Info-fontify-node ()
  2570.   (save-excursion
  2571.     (let ((case-fold-search t)
  2572.       (xref-regexp (concat "\\*"
  2573.                    (regexp-quote Info-footnote-tag)
  2574.                    "[ \n\t]*\\([^:]*\\):")))
  2575.       ;; Clear the old extents
  2576.       (map-extents #'(lambda (x y) (delete-extent x))
  2577.            (current-buffer) (point-min) (point-max) nil)
  2578.       ;; Break the top line iff it is > 79 characters.  Some info nodes
  2579.       ;; have top lines that span 3 lines because of long node titles.
  2580.       ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
  2581.       (toggle-read-only -1)
  2582.       (let ((extent nil)
  2583.         (len 0)
  2584.         (done nil)
  2585.         (p (point-min)))
  2586.     (goto-char (point-min))
  2587.     (re-search-forward "Node: *[^,]+,  " nil t)
  2588.     (setq len (- (point) (point-min))
  2589.           extent (make-extent (point-min) (point)))
  2590.     (set-extent-property extent 'invisible t)
  2591.     (while (not done)
  2592.       (goto-char p)
  2593.       (end-of-line)
  2594.       (if (< (current-column) (+ 78 len))
  2595.           (setq done t)
  2596.         (goto-char p)
  2597.         (forward-char (+ 79 len))
  2598.         (re-search-backward "," nil t)
  2599.         (forward-char 1)
  2600.         (insert "\n")
  2601.         (just-one-space)
  2602.         (backward-delete-char 1)
  2603.         (setq p (point)
  2604.           len 0))))
  2605.       (toggle-read-only 1)
  2606.       ;; Highlight xrefs in the top few lines of the node
  2607.       (goto-char (point-min))
  2608.       (if (looking-at "^File: [^,: \t]+,?[ \t]+")
  2609.       (progn
  2610.         (goto-char (match-end 0))
  2611.         (while
  2612.         (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
  2613.           (goto-char (match-end 0))
  2614.           (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref))))
  2615.       ;; Now get the xrefs in the body
  2616.       (goto-char (point-min))
  2617.       (while (re-search-forward xref-regexp nil t)
  2618.     (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
  2619.         nil
  2620.       (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref)))
  2621.       ;; then highlight the nodes in the menu.
  2622.       (goto-char (point-min))
  2623.       (if (and (search-forward "\n* menu:" nil t))
  2624.       (while (re-search-forward
  2625.           "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
  2626.         (Info-highlight-region (match-beginning 1) (match-end 1) 'info-node)))
  2627.       (set-buffer-modified-p nil))))
  2628.  
  2629. (defun Info-construct-menu (&optional event)
  2630.   "Construct a menu of Info commands.
  2631. Adds an entry for the node at EVENT, or under point if EVENT is omitted.
  2632. Used to construct the menubar submenu and popup menu."
  2633.   (or event (setq event (point)))
  2634.   (let ((case-fold-search t)
  2635.     (xref-regexp (concat "\\*" 
  2636.                  (regexp-quote Info-footnote-tag)
  2637.                  "[ \n\t]*\\([^:]*\\):"))
  2638.     up-p prev-p next-p menu xrefs subnodes in)
  2639.     (save-excursion
  2640.       ;; `one-space' fixes "Notes:" xrefs that are split across lines.
  2641.       (flet
  2642.       ((one-space (text)
  2643.               (let (i)
  2644.             (while (setq i (string-match "[ \n\t]+" text i))
  2645.               (setq text (concat (substring text 0 i) " "
  2646.                          (substring text (match-end 0))))
  2647.               (setq i (1+ i)))
  2648.             text)))
  2649.     (goto-char (point-min))
  2650.     (if (looking-at ".*\\bNext:") (setq next-p t))
  2651.     (if (looking-at ".*\\bPrev:") (setq prev-p t))
  2652.     (if (looking-at ".*Up:") (setq up-p t))
  2653.     (setq menu (nconc
  2654.             (if (setq in (Info-indicated-node event))
  2655.             (list (vector (one-space (cadr in)) in t)
  2656.                   "--:shadowEtchedIn"))
  2657.             (list
  2658.              ["Goto Info Top-level" Info-directory t]
  2659.              (vector "Next Node" 'Info-next next-p)
  2660.              (vector "Previous Node" 'Info-prev prev-p)
  2661.              (vector "Parent Node (Up)" 'Info-up up-p)
  2662.              ["Goto Node..." Info-goto-node t]
  2663.              ["Goto Last Visited Node " Info-last t])))
  2664.     ;; Find the xrefs and make a list
  2665.     (while (re-search-forward xref-regexp nil t)
  2666.       (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
  2667.                              (match-end 1)))
  2668.                 xrefs))))
  2669.       (setq xrefs (nreverse xrefs))
  2670.       (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
  2671.       ;; Find the subnodes and make a list
  2672.       (goto-char (point-min))
  2673.       (if (search-forward "\n* menu:" nil t)
  2674.       (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
  2675.     (setq subnodes (cons (buffer-substring (match-beginning 1)
  2676.                            (match-end 1))
  2677.                  subnodes))))
  2678.       (setq subnodes (nreverse subnodes))
  2679.       (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
  2680.     (if xrefs
  2681.     (nconc menu (list "--:shadowDoubleEtchedIn"
  2682.               "    Cross-References"
  2683.               "--:singleLine")
  2684.            (mapcar #'(lambda (xref)
  2685.                (if (eq xref 'more)
  2686.                    "...more..."
  2687.                  (vector xref
  2688.                      (list 'Info-follow-reference xref)
  2689.                      t)))
  2690.                xrefs)))
  2691.     (if subnodes
  2692.     (nconc menu (list "--:shadowDoubleEtchedIn"
  2693.               "      Sub-Nodes"
  2694.               "--:singleLine")
  2695.            (mapcar #'(lambda (node)
  2696.                (if (eq node 'more)
  2697.                    "...more..."
  2698.                  (vector node (list 'Info-menu node)
  2699.                      t)))
  2700.                subnodes)))
  2701.     menu))
  2702.  
  2703. (defun Info-menu-filter (menu)
  2704.   "This is the menu filter for the \"Info\" submenu."
  2705.   (Info-construct-menu))
  2706.  
  2707. (defun Info-select-node-menu (event)
  2708.   "Pops up a menu of applicable Info commands."
  2709.   (interactive "e")
  2710.   (select-window (event-window event))
  2711.   (let ((menu (Info-construct-menu event)))
  2712.     (setq menu (nconc (list "Info" ; title: not displayed
  2713.                 "     Info Commands"
  2714.                 "--:shadowDoubleEtchedOut")
  2715.               menu))
  2716.     (let ((popup-menu-titles nil))
  2717.       (popup-menu menu))))
  2718.  
  2719. ;;; Info toolbar support
  2720.  
  2721. ;; exit icon taken from GNUS
  2722. (defvar info::toolbar-exit-icon
  2723.   (if (featurep 'toolbar)
  2724.       (toolbar-make-button-list
  2725.        (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
  2726.              toolbar-icon-directory)))
  2727.   "Exit Info icon")
  2728.  
  2729. (defvar info::toolbar-up-icon
  2730.   (if (featurep 'toolbar)
  2731.       (toolbar-make-button-list
  2732.        (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
  2733.              toolbar-icon-directory)))
  2734.   "Up icon")
  2735.  
  2736. (defvar info::toolbar-next-icon
  2737.   (if (featurep 'toolbar)
  2738.       (toolbar-make-button-list
  2739.        (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
  2740.              toolbar-icon-directory)))
  2741.   "Next icon")
  2742.  
  2743. (defvar info::toolbar-prev-icon
  2744.   (if (featurep 'toolbar)
  2745.       (toolbar-make-button-list
  2746.        (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
  2747.              toolbar-icon-directory)))
  2748.   "Prev icon")
  2749.  
  2750. (defvar info::toolbar
  2751.   (if (featurep 'toolbar)
  2752. ; disabled until we get the next/prev-win icons working again.
  2753. ;      (cons (first initial-toolbar-spec)
  2754. ;       (cons (second initial-toolbar-spec)
  2755.          '([info::toolbar-exit-icon
  2756.          Info-exit
  2757.          t
  2758.          "Exit info"]
  2759.         [info::toolbar-next-icon
  2760.          Info-next
  2761.          t
  2762.          "Next entry in same section"]
  2763.         [info::toolbar-prev-icon
  2764.          Info-prev
  2765.          t
  2766.          "Prev entry in same section"]
  2767.         [info::toolbar-up-icon
  2768.          Info-up
  2769.          t
  2770.          "Up entry to enclosing section"]
  2771.         )))
  2772. ;))
  2773.  
  2774. (provide 'info)
  2775.  
  2776. (run-hooks 'Info-load-hook)
  2777.  
  2778. ;;; info.el ends here
  2779.